Accessing values in Excel with getValue

1557
2
Jump to solution
08-01-2012 12:30 PM
JonPedder
Occasional Contributor II
Hi, I'm reading in an Excel doc (xlsx) with arcpy and want to use row.getValue() to pull in the information by row and cell. I'm looking to use a SearchCursor() to access the excel file.

My Excel doc is Assignments.xlsx and the first worksheet is named Assignment, which would be referenced in Arc as Assignment$

I'm not sure how to access/read data in the cells?

Thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JonPedder
Occasional Contributor II
This appears to be working, if I select the worksheet first Assignments$

 import arcpy from arcpy import env arcpy.env.overwriteOutput = True  xcel = arcpy.GetParameterAsText(0) arcpy.AddMessage("Got Sheet")  rows = arcpy.SearchCursor(xcel) row = rows.next() arcpy.AddMessage("Got Rows")  while row:     arcpy.AddMessage("Start While")     # Loop through rowns and pull incident name from Incident_Name field     arcpy.AddMessage("Getting Assignment")          Assignment = row.getValue("Assignment_Number")     Description = row.getValue("Description")     arcpy.AddMessage(Assignment)     arcpy.AddMessage(Description)               arcpy.AddMessage("Received Assignment")     row = rows.next()


just getting started, thanks

View solution in original post

0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
I would suggest creating a tableview or permanent table depending on what you want to do with the data, and using a search cursor on that.
0 Kudos
JonPedder
Occasional Contributor II
This appears to be working, if I select the worksheet first Assignments$

 import arcpy from arcpy import env arcpy.env.overwriteOutput = True  xcel = arcpy.GetParameterAsText(0) arcpy.AddMessage("Got Sheet")  rows = arcpy.SearchCursor(xcel) row = rows.next() arcpy.AddMessage("Got Rows")  while row:     arcpy.AddMessage("Start While")     # Loop through rowns and pull incident name from Incident_Name field     arcpy.AddMessage("Getting Assignment")          Assignment = row.getValue("Assignment_Number")     Description = row.getValue("Description")     arcpy.AddMessage(Assignment)     arcpy.AddMessage(Description)               arcpy.AddMessage("Received Assignment")     row = rows.next()


just getting started, thanks
0 Kudos