Select to view content in your preferred language

Converting Excel files to GDB question

1487
2
Jump to solution
05-01-2012 10:22 AM
MichaelMiller2
Frequent Contributor
What is the proper method of accessing excel files using Python?

I'm using the below code and it returns the following error message:
ERROR 000732: Input Rows: Dataset 2005.xlsx does not exist or is not supported
Failed to execute (TableToTable).

import arcpy import os arcpy.env.overwriteOutput = 1 arcpy.env.workspace = r"\\itdhq1apt50\GIS_Data\Test_MM\KellyRawCrash" for file in arcpy.ListFiles("*.xlsx"):     outBase, outExt = os.path.splitext(file)     outCrash = "Crash" + outBase     print file     print outCrash     arcpy.TableToTable_conversion(file, gdb_loc, outCrash)


Michael Miller
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Honored Contributor
Here's an example of something close to what I do. Each sheet is it's own table.

import arcpy, os arcpy.env.workspace = r"C:\GIS\xlsxTest" outPath = r"C:\GIS\xlsxTest\output" fileList = arcpy.ListFiles("*.xlsx") for file in fileList:     arcpy.env.workspace = os.path.join(r"C:\GIS\xlsxTest", file)     tabList = arcpy.ListTables()      # Convert excel to DBF     tabNum = 0     for tab in tabList:         tabNum += 1         arcpy.TableToTable_conversion(tab, outPath, "Table"+tabNum+".dbf")

View solution in original post

0 Kudos
2 Replies
MathewCoyle
Honored Contributor
Here's an example of something close to what I do. Each sheet is it's own table.

import arcpy, os arcpy.env.workspace = r"C:\GIS\xlsxTest" outPath = r"C:\GIS\xlsxTest\output" fileList = arcpy.ListFiles("*.xlsx") for file in fileList:     arcpy.env.workspace = os.path.join(r"C:\GIS\xlsxTest", file)     tabList = arcpy.ListTables()      # Convert excel to DBF     tabNum = 0     for tab in tabList:         tabNum += 1         arcpy.TableToTable_conversion(tab, outPath, "Table"+tabNum+".dbf")
0 Kudos
MichaelMiller2
Frequent Contributor
Here's an example of something close to what I do. Each sheet is it's own table.

import arcpy, os
arcpy.env.workspace = r"C:\GIS\xlsxTest"
outPath = r"C:\GIS\xlsxTest\output"
fileList = arcpy.ListFiles("*.xlsx")
for file in fileList:
    arcpy.env.workspace = os.path.join(r"C:\GIS\xlsxTest", file)
    tabList = arcpy.ListTables()

    # Convert excel to DBF
    tabNum = 0
    for tab in tabList:
        tabNum += 1
        arcpy.TableToTable_conversion(tab, outPath, "Table"+tabNum+".dbf")



Thanks Matthew, that gets me over the hump.

Michael
0 Kudos