Table to Excel within Python script

12487
23
Jump to solution
06-16-2015 02:16 PM
CoyPotts1
Occasional Contributor III

I'm trying to export my feature class to a table, and then also create a copy as an Excel document.  The following code keeps kicking back with an error saying that I am using the wrong file type.

Error message:

"Failed to execute. Parameters are not valid.

ERROR 000814: Invalid file type

Failed to execute (TableToExcel)."

Code:

##########
# Create a file geodatabase for attribute tables to be saved in
##########


# Set local variables - uses variables derived earlier in script
attFolder = mapFolder + "/" + "6)Deliverables/4)Feature_Class_Attribute_Tables/" + version
outATTgdb = 'attribute_tables.gdb'

# Execute CreateFileGDB
arcpy.CreateFileGDB_management(attFolder, outATTgdb, 'CURRENT')


##########
# General Features export
##########

# Set local variables
inTable = generalFeatures
exportLoc = attFolder + "/" + outATTgdb
outTable = "general_attributes"
outXLS = "general_attributes.xls"

# Execute TableToTable
arcpy.TableToTable_conversion(inTable, exportLoc, outTable)

arcpy.env.workspace = 'attFolder'

# Execute TableToExcel
arcpy.TableToExcel_conversion(inTable, outXLS)









I've tried modifying this a bit, with no positive results.  For the outXLS variable I tried to make it equal the entire save location, and then removed the arcpy.env.workspace variable, but everything that I have tried results in the same "invalid file type" error.

Any recommendations?

Thanks in advance!

0 Kudos
23 Replies
DougHaller1
New Contributor III

Hi Coy

Did you resolve all the issues discussed above? If so, would you be willing to share the script?

I'm running into several similar challenges.  I would like to do the following: convert all the shapefiles in a gdb into spreadsheets and store the spreadsheets in their own folder or gdb. Eventually, I would like to convert this to a script tool that includes parameters for which gdb to search for shapefiles and where to store the final spreadsheets.  

Thanks, and I am new to Python, too.

0 Kudos
BlakeTerhune
MVP Regular Contributor

Hi Doug, welcome to GeoNet.

Are you getting an error message? Please describe your particular issue. Might help to post your code to review or even just start your own question thread.

0 Kudos
DougHaller1
New Contributor III

Thanks Blake. I will post my code shortly. Is it better to start a new thread or build on this thread as the original question appears similar?  I'm new to GeoNet.

Doug

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Probably best to start a new thread...but we can "branch" it too.

0 Kudos