SearchCursor + Excel .XLSX Files

3696
4
06-06-2012 01:15 PM
BenYoungs
New Contributor II
All,

I have several scripts that utilize the SearchCursor in ArcPy to pull info from .xls files, and it works very well. When I try the same approach using a Excel 2007+ .xlsx file, I get an "ERROR 999999: Error Executing Function". I read the following from the Desktop 10 Help:

If you have an .xlsx file you want to use in ArcGIS but do not have Excel 2007 installed, you will need to install the 2007 Office System Driver. It can be downloaded here from the Microsoft Download Center. If you have Microsoft Excel 2010 or no version of Microsoft Excel installed, you must install the 2007 driver before you can use either .xls or .xlsx files.


Now I realize I don't have Excel 2007 installed on my server, and I dont think I have the 2007 Office System Driver installed either. Funny thing is that I can view the .xlsx file through Catalog with no issues. So it doesnt seem like the driver is the issue.

Is there a known issue trying to use the SearchCursor with .xlsx files or is there a trick to this? I suppose I could go the route of pulling in another Python module to handle these files (XLRD?), but in my environment it is difficult to bring in outside software.

Thanks in advance for any advice you may have.
Tags (2)
0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Ben,

Can you post the code you are working with?  Be sure to wrap it in the CODE tags when posting.
0 Kudos
BenYoungs
New Contributor II
Jake,

Here is essentially what I have been doing which works perfect for an xls:
#Open spreadsheet with info
xls = <spreadsheet location>

# Create search cursor to parse spreadsheet info
rows = arcpy.SearchCursor(xls)

for row in rows:
     # Set username/password for each connection as variable
     user = row.USER
     password = row.PASSWORD


When I save that xls out as an xlsx and re-run I get the 99999 error.

Thanks,
Ben
0 Kudos
RaphaelR
Occasional Contributor II
hi Ben,

did you specify the worksheet (marked with the "$" sign at the end) as well, not just the .xslx file?
i get the 999999 error if i only point to the .xlsx files´location.

# this works
xls = r"J:\test\excelfile.xlsx\sheet1$"

# this doesn´t
xls1 = r"J:\test\excelfile.xlsx"

0 Kudos
BenYoungs
New Contributor II
Rafael,

Sorry, I forgot to include that in my code snippet before. Yes, I have been using "\Sheet1$" at the end of the path. So essentially all I am doing is changing the .xls to .xlsx in the spreadsheet path and then I get the error thrown.

hi Ben,

did you specify the worksheet (marked with the "$" sign at the end) as well, not just the .xslx file?
i get the 999999 error if i only point to the .xlsx files´location.

# this works
xls = r"J:\test\excelfile.xlsx\sheet1$"

# this doesn´t
xls1 = r"J:\test\excelfile.xlsx"

0 Kudos