I am currently trying to create a python script within ModelBuilder to convert an xls file to csv.

I created one already using the "Table to CSV" tool which was successful. However, I tried to add data to the xls file and run the script again and it choked on the "csv already exists". I tried adding "Application.DisplayAlerts = False" to overwrite the csv already existing, but it still choked when I tried to run it again. (Script and error code below)


# Import arcpy module
import arcpy

# Load required toolboxes
arcpy.ImportToolbox("C:/Temp/Excel_and_CSV_Conversion_Tools/ExcelTools/Excel and CSV Conversion Tools.tbx")

# Local variables:
Sheet1_ = "R:\\Workspace\\Es\\Employee\\Maggie\\OptOut\\Test.xlsx\\Sheet1$"
test_csv = "R:\\Workspace\\Es\\Employee\\Maggie\\OptOut\\test.csv"

# Process: TableToCSV
arcpy.TableToCSV_tableconversion(Sheet1_, test_csv, "COMMA")


ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Table Name: Dataset R:\Workspace\Es\Employee\Maggie\OptOut\Test.xlsx\Sheet1$ does not exist or is not supported
ERROR 000725: Output CSV: Dataset R:\Workspace\Es\Employee\Maggie\OptOut\test.csv already exists.
Failed to execute (TableToCSV).

My ultimate goal is to create a script I can set up in task scheduler to run on it's own everyday to convert an xls to csv, without using a script that requires macros to be enabled in the xls.

I am at the beginner beginner level when it comes to python script.

  • I guess you are unaware of the ESRI code sharing website? Why bother writing all this code when the tools already exists here? – Hornbydd Feb 12 '19 at 22:29

Try setting the arcpy environment property to true in the beginning of the script

arcpy.env.overwriteOutput = True

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.