Created
February 26, 2016 19:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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