我终于找到了一种方法来做到这一点。我想我会将我的代码发布给任何可能遇到相同情况的人。我使用一些GIS文件,但如果不这样做,可以将变量设置为目录路径,而不是使用env.workspace,并使用游标搜索而不是arcpy.SearchCursor函数,那么这是可行的。
import arcpy, xlwt
from arcpy import env
from xlwt import Workbook
# Set the workspace. Location of feature class or dbf file. I used a dbf file.
env.workspace = "C:\data"
# Use row object to get and set field values
cur = arcpy.SearchCursor("SMU_Areas.dbf")
# Set up workbook and sheet
book = Workbook()
sheet1 = book.add_sheet('Sheet 1')
book.add_sheet('Sheet 2')
# Set counter
rowx = 0
# Loop through rows in dbf file.
for row in cur:
rowx += 1
# Write each row to the sheet from the workbook. Set column index in sheet for each column in .dbf
sheet1.write(rowx,0,row.ID)
sheet1.write(rowx,1,row.SHAPE_Area/10000)
book.save('C:\data\MyExcel.xls')
del cur, row
嘿丹尼尔,这是我最终做的。感谢您的指导。我会用我的代码回答我的问题。 – Mike