I have several Excel files that contain several sheets. I need to convert these files into one table in gdb. I wrote script that convert the whole sheet in separate table. How can I export a range (f.e. A8:G(rows on the sheet)) of the sheet to one table.

import arcpy, os, xlrd,xlwt
from arcpy import env

arcpy.env.overwriteOutput = True

fname = 'D:/excel_files/exc4.xls'
output_gdb = "D:/P01_ExctoGDB/GDB_EXC.gdb"
# Open the workbook
rb = xlrd.open_workbook(fname)

# List sheet names, and pull a sheet by name
sheet_names = rb.sheet_names()

for i in range(0,len(sheet_names)):
    vals=[sheet.row_values(8) for rownum in range(sheet.nrows)]

    outTablename= output_gdb+"/"+str(sheet_names[i]).replace(" ",'').replace(".","")
    arcpy.ExcelToTable_conversion(fname,outTablename, sheet_names[i])

  • You can't limit how much of the spreadsheet you convert via arcpy to the extent of my knowledge. You would have to delete rows from your GIS table post-conversion. – Emil Brundage Sep 23 '19 at 20:54
  • @EmilBrundage, yes it is good idea, thank you. – Lora Sep 24 '19 at 5:32

I suggest taking a look at Understanding how to use Microsoft Excel files in ArcGIS which says:

When accessed from ArcGIS, a worksheet is shown as a table with a dollar sign ($) at the end of its name, but a named range does not have a dollar sign. Worksheets or named ranges with names containing spaces have single quotation marks placed around the table name.

I do little with Excel files but I think it is a named range that you need to use.

| improve this answer | |

As @EmilBrundage advised I just deleted first rows.

with arcpy.da.UpdateCursor(outTablename,"OBJECTID","OBJECTID >=1 AND OBJECTID <7") as cursor:
     for row in cursor:
| improve this answer | |

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.