4

I have an arcpy script that works on one machine, but fails very early on another.

import arcpy, os

arcpy.env.overwriteOutput = True

xlFile = r"D:\GIS\mt\data\ExcelTable.xlsx"
outGDB = r"D:\GIS\mt\data\Data.gdb"
arcpy.env.workspace = outGDB
mapTable= "xxExcelOutput"
inMemMapTable= r"in_memory\xxExcelOutput"

sheetName = r"Map Sheet"

arcpy.ExcelToTable_conversion(xlFile, inMemMapTable, sheetName)

It fails on the arcpy.ExcelToTable_conversion() with the following error message:

Traceback (most recent call last):
  File "D:\GIS\mt\readexcel.py", line 13, in <module>
    arcpy.ExcelToTable_conversion(xlFile, inMemMapTable, sheetName)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\conversion.py", line 60, in ExcelToTable
    retval = convertArcObjectToPythonObject(gp.ExcelToTable_conversion(*gp_fixargs((Input_Excel_File, Output_Table, Sheet), True)))
ExecuteError: 
Traceback (most recent call last):
  File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\ExcelToTable.py", line 252, in <module>
    arcpy.GetParameterAsText(2))
  File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\ExcelToTable.py", line 203, in excel_to_table
    out_fields = gen_out_fields(workbook, sheet, out_path, is_gdb)
  File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\ExcelToTable.py", line 175, in gen_out_fields
    out_fields.append(clsField(f, out_path, is_gdb, out_fields))
  File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\ExcelToTable.py", line 33, in __init__
    if not name[0].isalpha():
IndexError: string index out of range

Failed to execute (ExcelToTable).

The machine it works on is running 10.3.1, and it fails on 10.5. I thought maybe there was a change/difference in parameter requirements in 10.5, so in ArcMap I ran just the Excel to Table tool from ArcToolbox

enter image description here

and I get pretty much the same error:

Executing: ExcelToTable D:\GIS\mt\ExcelTable.xlsx in_memory\xxExcelOutput "Map Sheet"
Start Time: Tue Mar 21 09:30:15 2017
Running script ExcelToTable...
Failed script ExcelToTable...

Traceback (most recent call last):
  File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\ExcelToTable.py", line 252, in <module>
    arcpy.GetParameterAsText(2))
  File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\ExcelToTable.py", line 203, in excel_to_table
    out_fields = gen_out_fields(workbook, sheet, out_path, is_gdb)
  File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\ExcelToTable.py", line 175, in gen_out_fields
    out_fields.append(clsField(f, out_path, is_gdb, out_fields))
  File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\ExcelToTable.py", line 33, in __init__
    if not name[0].isalpha():
IndexError: string index out of range

Failed to execute (ExcelToTable).
Failed at Tue Mar 21 09:30:16 2017 (Elapsed Time: 1.20 seconds)

What could be causing my arcpy to not be able to read my Excel file, and how do I fix it?

The Excel file was originally an export from Google Sheets, so I re-saved it in Excel with no effect. I removed spaces from the file name and the sheet name, also with no effect.

I created another Excel file with a similar filename and sheet name but with dummy data, and this has worked successfully, so I suspect now there's something in my original file that the Excel to Table tool doesn't like, but I am unsure what to look for, particularly because the exact same file works fine on another machine.

2
  • 2
    My guess is the issue is a bad column cell value. I would start removing one column at a time and run the tool and see if you can identify which column has the bad character. Once you figure out the column then comes the fun part on finding the bad value(s).
    – artwork21
    Commented Mar 21, 2017 at 17:13
  • What happens if you open ArcGIS and use 'Add data' to add the Excel sheet to a map document? This might give you a better error message if it fails, or if it works you might get more insight into what's going on by inspecting the loaded table.
    – Alexander
    Commented Mar 21, 2017 at 17:24

2 Answers 2

2

Your error message seems to stop at the line calling the function isalpha(). According to python help isalpha() returns:

true if all characters in the string are alphabetic and there is at least one character, false otherwise.

So either you have an empty column header (may be its hidden?) or its starting with a number which would be an invalid header for an in_memory table which you are converting to.

1
  • There was a blank column header in the sheet - giving it a name made the process work. Not sure why it works without error on my 10.3.1 machine but fails on 10.5 - maybe a change behind the scenes in that tool?
    – Midavalo
    Commented Mar 21, 2017 at 18:47
0

Same problem was in my case. Problem was solved by setting excel file, i.e. column name, and column type . Worked for me both way, reading and writing to excel to and from arcgis.

1
  • 2
    Can you expand on what you mean by setting excel file,
    – nmtoken
    Commented Aug 19, 2020 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.