Error: Using Search Cursor on XLS File

555
5
02-19-2014 12:34 PM
MikeMacRae
Occasional Contributor III
I am trying to cursor search through a .xls file using
arcpy.SearchCursor


My code is this:
xls = r"\\spatialfiles.work\Local\scripts\python\Excel\Report.xls\'Dataset selection$'"

for row in arcpy.SearchCursor(xls):
     print row.getValue("Layer")

I'm baffled. Yesterday this code worked fine. Today I am getting an error:

IOError: "\\spatialfiles.work\Local\scripts\python\Excel\Report.xls\'Dataset selection$'"
does not exist


The xls file does exist. I can navigate to it in ArcCataloge without issue and view the table. The path is correct because I copied and pasted it right out of Catalogue.

Can anyone suggest why this is occuring?


Thanks,
Mike
Tags (2)
0 Kudos
5 Replies
JamesCrandall
MVP Frequent Contributor
Just a shot in the dark here, but could the problem be the file extension?  Are you sure it is ".xls" and not ".xlsx"?
0 Kudos
MikeMacRae
Occasional Contributor III
Thanks for checking, but yes. It's .xls. I copied and pasted the path straight from Catalogue.

The other weird anamolay is that, I can write the script through the python shell, line for line adn then it will work. When I do it from the pything window as a script, it throws that same error all the time.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Thanks for checking, but yes. It's .xls. I copied and pasted the path straight from Catalogue.

The other weird anamolay is that, I can write the script through the python shell, line for line adn then it will work. When I do it from the pything window as a script, it throws that same error all the time.


Maybe related to 64-bit processing?  Have a look at the .xls/.xlsx reference in this:

http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000040000000

Sorry for such abstract answers, I find this topic entirely confusing and have not had to deal with these issues as of yet.
0 Kudos
AdamCox1
Occasional Contributor II
I was having the exact same issue yesterday.  I was using  I kind of resolved it, but still don't quite know what's going on.  One thing I noticed was that while I was in ArcMap and looking at the excel files in the ArcCatalog window, whenever I was getting the error I was also not able to expand the xls file to show the individual sheets within it.  I would get a "dataset doesn't exist or is not supported" type of error.  Basically, I'm thinking that it comes down to some sort of permissions issue.  I was able to get things to work by alternately closing the python shell/IDLE as well as reopening ArcMap.  Also, refreshing the folder in the catalog window helps.  Eventually I was able to expand the file in the catalogue window, and also run the scripts.

Not sure if this is helpful, but good luck!  It may be worth importing the table to a geodatabase, and using it from there.
0 Kudos
MikeMacRae
Occasional Contributor III
I decided to try the code in Ecvlsipe instead of IDLE. It works there, so I'm lead to believe thatit's an IDLE issue. I've had these issues before, so I think I'm done with using IDLE.
0 Kudos