So what I'm trying to do is to create feature classes from the sheets in an Excel table. I can get it to work if I save each excel sheet as its own workbook, however this isn't really what I want. I an a complete newbie so I'm sure the answer is pretty obvious. I think it is something to do with the $ in the table names, I can't work out how to strip it though. Any help would be much appreciated, Thanks
Working code
fileList = arcpy.ListFiles("*.xlsx")
print 'Listing .xlsx files in workspace'
try:
# Loop through each file
for file in fileList:
print file
arcpy.env.workspace = os.path.join(r"C:\\Users\\Jane\\Documents\\GIS Project\\BasicTest", file)
# Use splitext to set the output name of the table
dbfFile = os.path.splitext(file)[0] #+ ".xlsx"
if arcpy.Exists(dbfFile+".dbf"):
print "deleting"
arcpy.Delete_management(dbfFile+".dbf")
# Convert excel to DBF
arcpy.TableToTable_conversion("Sheet1$", outPath, dbfFile+ ".dbf")
print 'File conversion. Converted ' + file
Not working code:
tableList = arcpy.ListTables()
print 'Listing table files in sheet'
for table in tableList:
print table
arcpy.env.workspace = os.path.join(r"C:\\Users\\Jane\\Documents\\GIS Project", table)
# Use splitext to set the output name of the table
dbfFile = os.path.splitext(table)[0] #+ ".xlsx"
if arcpy.Exists(dbfFile+".dbf"):
print "deleting"
arcpy.Delete_management(dbfFile+".dbf")
# Convert excel to DBF
arcpy.TableToTable_conversion(table, outPath, dbfFile+ ".dbf")
print 'File conversion. Converted ' + table
Error:
Traceback (most recent call last):
File "C:/Users/Jane/Documents/GIS Project/BasicTest/3rd Script.py", line 33, in <module>
arcpy.TableToTable_conversion(table, outPath, dbfFile+ ".dbf")
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\conversion.py", line 1904, in TableToTable
raise e
ExecuteError: ERROR 000354: The name contains invalid characters
Failed to execute (TableToTable).