Select to view content in your preferred language

Issues to work with Excel files with arcPy!!

4955
13
09-22-2015 08:05 AM
SaidAkif
Occasional Contributor

Hi all

I tried to convert excel sheets to table. I did the folowing:

code1.PNG

the problem that I got a message 000732 that imput table table .....\file.xlsx\'ATL...$' does not exist or not supported (makeTableView).

the list (Listxls) is well populated. Moreover, I tried the same work at home and it work fine. I really don't know what happen?

Any help please?

By the way, I hve lot of trouble to use this webside. I can't copy/paste anything. My interface is :

code2.PNG

Thanks in advance

0 Kudos
13 Replies
WesMiller
Deactivated User

This happens when you run a program a second time and you don't use "arcpy.env.overwriteOutput = True". If this a repeat add the line of code and rerun, I would suggest if this is not a test environment meaning you don't need the data in the geodatabase, I would make a back up copy.

0 Kudos
BlakeTerhune
MVP Regular Contributor

When using TableToTable_conversion() from Excel to GDB, you need to specify the sheet name suffixed with a $. Something like C:/temp/MyExcelFile.xlsx/mySheetName$

Using the Esri code samples in the Excel To Table link provided by Rebecca Strauch, GISP, you can use the xlrd module for reading the sheets in an Excel file.

import os
import xlrd
import arcpy

def main():
    # Local variables
    in_excel = r"C:\temp\MyExcelFile.xlsx"
    out_gdb = r"C:\temp\MyGeodatabase.gdb"

    # Read Sheets in Excel Workbook
    with xlrd.open_workbook(in_excel) as workbook:
        sheets = [sheet.name for sheet in workbook.sheets()]

        # Export each sheet to geodatabase table
        for sheet in sheets:
            in_rows = os.path.join(in_excel,str(sheet)+"$")
            ## The out_name is based on the input excel file name
            ## an underscore (_) separator followed by the sheet name
            baseName = os.path.basename(in_excel)
            out_name = arcpy.ValidateTableName(
                "{0}_{1}".format(os.path.splitext(baseName)[0], sheet),
                out_gdb
            )
            arcpy.TableToTable_conversion(in_rows, out_gdb, out_name,)
            print arcpy.GetMessages(), "\n"


if __name__ == '__main__':
    main()
RebeccaStrauch__GISP
MVP Emeritus

Said, as a side note on the copy-paste in Geonet, have you seen Posting Code blocks in the new GeoNet​ ?  Main things to remember is the "advanced editor" tab won't show if you are replying within you Geonet inbox....make sure to right-click on the header/title of you question and "open in another tab" .... Opening from you system inbox may work to.

my opologies if you had already seen that post....posting code isn't always consistent.

0 Kudos
StevenEnsing
Occasional Contributor

As another approach, for work with pre-10.2, you might find the Excel and CSV conversion toolbox download from Esri useful: similar tools to what's included in 10.2, plus a csv to table tool.

http://www.arcgis.com/home/item.html?id=f3d91b8f852042e289e09a7ec8342431