TransWikia.com

Excel to Table failing

Geographic Information Systems Asked by Midavalo on December 3, 2020

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:GISmtdataExcelTable.xlsx"
outGDB = r"D:GISmtdataData.gdb"
arcpy.env.workspace = outGDB
mapTable= "xxExcelOutput"
inMemMapTable= r"in_memoryxxExcelOutput"

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:GISmtreadexcel.py", line 13, in <module>
    arcpy.ExcelToTable_conversion(xlFile, inMemMapTable, sheetName)
  File "C:Program Files (x86)ArcGISDesktop10.5ArcPyarcpyconversion.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)arcgisdesktop10.5ArcToolboxScriptsExcelToTable.py", line 252, in <module>
    arcpy.GetParameterAsText(2))
  File "c:program files (x86)arcgisdesktop10.5ArcToolboxScriptsExcelToTable.py", line 203, in excel_to_table
    out_fields = gen_out_fields(workbook, sheet, out_path, is_gdb)
  File "c:program files (x86)arcgisdesktop10.5ArcToolboxScriptsExcelToTable.py", line 175, in gen_out_fields
    out_fields.append(clsField(f, out_path, is_gdb, out_fields))
  File "c:program files (x86)arcgisdesktop10.5ArcToolboxScriptsExcelToTable.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:GISmtExcelTable.xlsx in_memoryxxExcelOutput "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)arcgisdesktop10.5ArcToolboxScriptsExcelToTable.py", line 252, in <module>
    arcpy.GetParameterAsText(2))
  File "c:program files (x86)arcgisdesktop10.5ArcToolboxScriptsExcelToTable.py", line 203, in excel_to_table
    out_fields = gen_out_fields(workbook, sheet, out_path, is_gdb)
  File "c:program files (x86)arcgisdesktop10.5ArcToolboxScriptsExcelToTable.py", line 175, in gen_out_fields
    out_fields.append(clsField(f, out_path, is_gdb, out_fields))
  File "c:program files (x86)arcgisdesktop10.5ArcToolboxScriptsExcelToTable.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 Answers

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.

Correct answer by Hornbydd on December 3, 2020

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.

Answered by Maria Sheikh on December 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP