Skip to content

Instantly share code, notes, and snippets.

@cindygis
Last active August 29, 2015 14:16
Show Gist options
  • Save cindygis/b69452ace6d010632fa3 to your computer and use it in GitHub Desktop.
Save cindygis/b69452ace6d010632fa3 to your computer and use it in GitHub Desktop.
Takes a folder of spreadsheets and converts it to geodatabase tables using available arcpy tools.
#
# @author Cindy Williams
# @date 14/11/2014
#
# Takes a folder containing deeds data in spreadsheet
# format and converts it into a GIS table for further processing.
# It must adhere to a specific format.
#
# For use as a script tool in an ArcGIS Toolbox.
#
import arcpy
import os
import sys
# Input variables
fld = arcpy.GetParameterAsText(0)
gdb = arcpy.GetParameterAsText(1)
sheet_name = "Sheet"
for root, dirs, filenames in os.walk(fld):
for f in filenames:
try:
arcpy.AddMessage("Processing " + f)
xls = os.path.join(root, f)
name = os.path.splitext(f)[0]
for i in name:
if i in ["-", " ", "."]:
name = name.replace(i, "_")
tbl = os.path.join(tbl, name)
arcpy.conversion.ExcelToTable(xls, tbl, sheet_name)
arcpy.AddMessage("Processed " + name)
except:
e = sys.exc_info()[0]
arcpy.AddMessage("Error caught: ")
arcpy.AddMessage(e)
arcpy.AddMessage("Processing complete.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment