I wrote the script below to iterate through a file geodatabase's feature classes and convert them to an excel table. However, it returns the error

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000814: Invalid file type
Failed to execute (TableToExcel)

I converted the feature classes to table views but I can't figure out what is wrong with the paramaters. The error is at line 18, which is where the arcpy.TableToExcel_conversion('table', outname) operation begins.

import arcpy
from arcpy import env

env.workspace = r'C:\Parishes\Cameron.gdb'
parish = "Cameron"

for fc in arcpy.ListFeatureClasses():

    if arcpy.Exists('tableview'): 

    arcpy.MakeTableView_management(fc, 'tableview') 

    outname = str(fc) + parish + ".xls"

    arcpy.TableToExcel_conversion('tableview', outname)
    arcpy.AddMessage('Created "{}" Table export '.format(fc))

  • 3
    I think your output file name needs to end in .xls – Mintx May 27 '15 at 20:53
  • 3
    What is dbSpace? If this is not a valid folder, you'll likely get the same error. – DWynne May 27 '15 at 21:07
  • 1
    sure - outname = os.path.join('someotherdirectory',fc.replace(".","_")) (at least i think so - if fc is the feature class name only) – fluidmotion May 27 '15 at 21:16
  • 1
    Still need to add on the .xls extension as per @Mintx – DWynne May 27 '15 at 21:20
  • 2
    @TacoB0t you should really hard code the values in first before messing around with GetParameterAsText(). It makes debugging a lot easier. – ianbroad May 27 '15 at 21:41

As a test I suggest trying to change:

outname = str(fc) + parish + ".xls"


outname = 'C:\\Parishes\\' + str(fc) + parish + ".xls"

I suspect that trying to write a *.xls to a *.gdb (even though that is a folder) is what may be upsetting the tool.

  • After dancing around the solution, this was the perfect syntactical combination to get it working! Thanks! – TacoB0t May 27 '15 at 22:02
  • The combination of comments had the answer an hour ago. – DWynne May 27 '15 at 22:12
  • @DWynne That may be a lesson to the asker about how important it is to keep editing the question to keep it in sync with testing and advice being given. meta.gis.stackexchange.com/a/3353 – PolyGeo May 27 '15 at 22:24
  • @PolyGeo. My comment was more to the first comment on this answer, not the answer itself. 'Dancing around the solution' seems unfair and downplays the time and contribution of several people. – DWynne May 27 '15 at 22:42
  • @DWynne That was what I figured. For this question it seemed like a "discussion in comments" was taking the place of comments being used to suggest problems in the question as asked, and then the asker addressing those via edits to the question rather than a convoluted comment trail (aka why I tired of discussion forums). – PolyGeo May 27 '15 at 22:46

@PolyGeo's answer is accurate. But I just want to draw attention to the use of table views in the original case; they shouldn't be necessary. Code could be simplified down to something like this:

import arcpy
import os

arcpy.env.workspace = r'C:\Parishes\Cameron.gdb'
parish = "Cameron"

# use other folder as needed
out_folder = arcpy.env.scratchFolder  

for fc in arcpy.ListFeatureClasses():

    name = os.path.splitext(fc)[0]  # remove extensions if any
    outname = os.path.join(out_folder, "{}{}.xls".format(name, parish))

    arcpy.TableToExcel_conversion(fc, outname)
    arcpy.AddMessage('Created "{}" Table export '.format(fc))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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