Excel To Table

Titleā€ƒ Excel To Table

Summary

Geoprocessing tool that converts Microsoft Excel files into a table.


Usage


Syntax

Parameter Explanation
Input_Excel_File (Optional)

The Microsoft Excel file to convert.

Output_Table

The output table.

Sheet

The name of the particular sheet within the Excel file to import. If unspecified, the first sheet in the workbook will be used.

esri_out_feature_service_name (Optional)

The name of the optional feature service to create on the federated server containing the result of this tool. If no name is specified an output feature service will not be created.

Code Samples

ExcelToTable example (Python window)

The following Python window script demonstrates how to use the ExcelToTable function in immediate mode.


import arcpy
arcpy.env.workspace = "c:/data"
arcpy.ExcelToTable_conversion("data.xls", "outgdb.gdb", "Sheet1")

                    

ExcelToTable example 2 (stand-alone script)

Import each sheet in a Microsoft Excel file into individual tables in a 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')

                    

Tags

Credits

Use limitations