Script to import Excel files

1714
4
Jump to solution
05-31-2016 11:11 AM
MarleneSanchez
New Contributor

I am trying to create a script to import a few properly formatted excel files into ArcMap with the Excel to Table conversion tool.

The script is throwing an exception saying "Filed in invalid".

But when I import the same excel files manually in ArcMap, it succeeds without error!

If all the script is doing is passing the files to the conversion tool (that succeeds on its own with every file), why doesn't the script execute? 

Is it because I don't have an exception handling procedure that the Excel to Table conversion tool needs?

Here is the code:

<code>

import arcpy

import os

arcpy.env.workspace="C:\Desktop\AP_MAP_WORKUP\Formatted_Table_Info_for_GIS"

   for file in arcpy.ListFiles("*.xl*"):

           filename = os.path.splitext(file)[0]

           arcpy.ExcelToTable_conversion(file,filename+"_import")

<code>

Here is the error:

Runtime error  Traceback (most recent call last):   File "<string>", line 3, in <module>   File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\conversion.py", line 44, in ExcelToTable     raise e ExecuteError:  Traceback (most recent call last):   File "c:\program files (x86)\arcgis\desktop10.3\ArcToolbox\Scripts\ExcelToTable.py", line 252, in <module>     arcpy.GetParameterAsText(2))   File "c:\program files (x86)\arcgis\desktop10.3\ArcToolbox\Scripts\ExcelToTable.py", line 223, in excel_to_table     template=tmp_table)   File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 15306, in CreateTable     raise e ExecuteError: ERROR 999999: Error executing function. The name of the Field is invalid: valid names may contain letters, numbers or underscores. Failed to execute (CreateTable).   Failed to execute (ExcelToTable).

0 Kudos
1 Solution

Accepted Solutions
ChrisSmith7
Frequent Contributor

Per the error message:

ERROR 999999: Error executing function. The name of the Field is invalid: valid names may contain letters, numbers or underscores. Failed to execute (CreateTable).   Failed to execute (ExcelToTable).

I would make sure all of your field names meet these requirements. You can try on a dummy file with one column meeting the criteria and one with spaces to see if it's reproducible.

View solution in original post

4 Replies
BenjaminMittler
Occasional Contributor III

At first glance, the "for" line shouldn't be indented.

ChrisSmith7
Frequent Contributor

Per the error message:

ERROR 999999: Error executing function. The name of the Field is invalid: valid names may contain letters, numbers or underscores. Failed to execute (CreateTable).   Failed to execute (ExcelToTable).

I would make sure all of your field names meet these requirements. You can try on a dummy file with one column meeting the criteria and one with spaces to see if it's reproducible.

MarleneSanchez
New Contributor

It worked fine on a dummy file.

What's odd is that the conversion works fine with the files as they are when done manually with the Excel to Table tool in ArcMap

0 Kudos
BenjaminMittler
Occasional Contributor III

When you run the conversion in arcmap is it saving to the folder in your script or is it saving the table in your default.gdb. I find fhe Excel to Table tool is always much more friendly when saving to a gdb

0 Kudos