Excel in Tabelle (Konvertierung)

Lizenzstufe:BasicStandardAdvanced

Zusammenfassung

Konvertiert Microsoft Excel-Dateien in eine Tabelle.

Verwendung

Syntax

ExcelToTable_conversion (Input_Excel_File, Output_Table, {Sheet})
ParameterErläuterungDatentyp
Input_Excel_File

Die zu konvertierende Microsoft Excel-Datei.

File
Output_Table

Dies ist die Ausgabetabelle.

Table
Sheet
(optional)

Der Name des Arbeitsblattes in der zu importierenden Excel-Datei. Falls nichts angegeben ist, wird standardmäßig die erste Arbeitsmappe verwendet.

String

Codebeispiel

ExcelToTable – Beispiel (Python-Fenster)

Das folgende Skript im Python-Fenster veranschaulicht, wie die Funktion "ExcelToTable" im unmittelbaren Modus verwendet wird.

import arcpy
arcpy.env.workspace = "c:/data"
arcpy.ExcelToTable_conversion("data.xls", "outgdb.gdb", "Sheet1")
ExcelToTable – Beispiel 2 (eigenständiges Skript)

Importiert jedes Arbeitsblatt einer Microsoft Excel-Datei in einzelne Tabellen in einer Geodatabase.

import os
import xlrd
import arcpy

def importallsheets(in_excel, out_gdb):
    workbook = xlrd.open_workbook(in_excel)
    sheets = [sheet.name for sheet in workbook.sheets()]

    print('{} sheets found: {}'.format(len(sheets), ','.join(sheets)))
    for sheet in sheets:
        # The out_table is based on the input excel file name
        # a underscore (_) separator followed by the sheet name
        out_table = os.path.join(
            out_gdb,
            arcpy.ValidateTableName(
                "{0}_{1}".format(os.path.basename(in_excel), sheet),
                out_gdb))

        print('Converting {} to {}'.format(sheet, out_table))

        # Perform the conversion
        arcpy.ExcelToTable_conversion(in_excel, out_table, sheet)

if __name__ == '__main__':
    importallsheets('c:/data/data.xls',
                    'c:/data/outgdb.gdb')

Umgebung

Verwandte Themen

Lizenzierungsinformationen

ArcGIS for Desktop Basic: Ja
ArcGIS for Desktop Standard: Ja
ArcGIS for Desktop Advanced: Ja
6/5/2014