Skip to content

Instantly share code, notes, and snippets.

@AlexArcPy
Created February 26, 2016 19:18
Show Gist options
  • Save AlexArcPy/db18d1237935361a4b26 to your computer and use it in GitHub Desktop.
Save AlexArcPy/db18d1237935361a4b26 to your computer and use it in GitHub Desktop.
Export attribute table of a fc to an Excel workbook with xlsxwriter site-package
import xlsxwriter
import arcpy
workbook = xlsxwriter.Workbook('ResearchAreas.xlsx')
worksheet = workbook.add_worksheet()
fc = r"C:\ArcTutor\GP Service Examples\ClipAndShip\ToolData\Zion.gdb\Research_areas"
fields = [f.name for f in arcpy.ListFields(fc) if f.name.upper() not in ("OBJECTID","SHAPE")]
rows = [r for r in arcpy.da.SearchCursor(fc,fields)]
rows_structured = [list(elem) for elem in rows]
rows_structured.insert(0,fields)
for i, row in enumerate(rows_structured):
worksheet.write_row(i, 0, row)
workbook.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment