Reading Excel sheet in ArcPy script?

It doesn't work because you haven't called the Xlrd modules to read the Excel spreadsheet. Implement it something like this:

import xlrd
workbook = xlrd.open_workbook('my_workbook.xls')
worksheet = workbook.sheet_by_name('Sheet1')

This will allow you to read an XLS file with Python. However, ArcPy will read XLS without Xlrd. You can consider the Excel workbook to be a workspace containing potentially many tables (worksheets). So you could do something like:

arcpy.env.workspace = r'E:\123.xls'
input_table = 'Sheet1$'

...or cut to the chase with:

arcpy.MakeXYEventLayer_management(r'E:\123.xls\Sheet1$',lat,long,layername,SpatialRef)

You do not mention your ArcGIS for Desktop version, but if it is 10.2 (or later) then you should be able to use the Excel To Table tool which:

Converts Microsoft Office Excel files into a table.

Its syntax is:

ExcelToTable_conversion (Input_Excel_File, Output_Table, {Sheet})

Tags:

Python

Excel