roy_hewitt

Batch import Excel files for processing

Discussion created by roy_hewitt on Aug 12, 2011
Latest reply on May 30, 2014 by kimo
Hello all,

I'm trying to write a script tool for one of our field biologists to process data.  XY data is contained in several excel files all saved to the same folder.  I'm using the table to table tool (Conversion tools) followed by Make XY Event Layer (Data Management).

I've tried the ListTables() command, but it isn't finding any of the .xls files.  Here is an example of my code.


import arcpy
arcpy.env.workspace = "C:/Documents and Settings/RHewitt/Desktop/SAV Report files 2010/"
outPath = "C:/Documents and Settings/RHewitt/Desktop/SAV Report files 2010/Output/"


# Local variables:
xVal = "Longitude"
yVal = "Latitude"
projWGS = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119521E-09;0.001;0.001;IsHighPrecision"

# List all files in folder, then list all tables in file
fileList = arcpy.ListFiles()
tableList = arcpy.ListTables()

try:
    # Loop through each table
    for file in fileList:
        for table in tableList:
            # Convert excel to DBF, make XY event layer, save to output
            arcpy.TableToTable_conversion(table, outpath, table)
            arcpy.MakeXYEventLayer_management(table, xVal, yVal, "now_" + table, projWGS)
            arcpy.CopyFeatures_management("now_" + table, outpath + table)
except:
    print arcpy.GetMessages()


Thanks,
Roy

Outcomes