Export feature class attribute table into an Excel 2007 with xlsxwriter

Did you ever need to export the attribute table of your feature class into an Excel workbook? I am fairly sure you did. Maybe someone without ArcMap needed to take a look at a piece of data or build a graph within the Excel based on the attributes. You just need to take some of your data into an enterprise system that require an Excel file as input.

Previously, before the ArcGIS 10.2 was released, you had to build custom Python scripts for exporting the attributes. There are some custom scripts that were made available for 10.0+ users, too. Alternatively, you could export the attribute table into a .txt/.csv file which you could later import in Excel. Take a look at this Esri KB article HowTo: Export an attribute table to Microsoft Excel to learn more.

At 10.2, script tools Table to Excel and Excel to Table were made available in ArcGIS for Desktop for all license levels. These tools are based on the xlwt Python site package. However, these tools can work only with .xls files (Excel 97-2003 format) which means you won’t be able to generate an Excel from a feature class with more than 65,536 rows.

I’ve recently needed to generate multiple Excel files from rather large feature classes with some fancy styling; this is where another Python site package – xlsxwriter – came handy. It provides a very clean and fast interface for creating new Excel files. In fact, generating an Excel file from a feature class (much like what the Table to Excel geoprocessing tool does) can be done in this very snippet of code.

Keep in mind that it would be very easy to filter out what rows you want to export by using a where clause within the cursor definition. The xlsxwriter has an amazing suite of features for doing very fancy things within an Excel workbooks such as generating charts, using formulas, and provide data validation rules. The project is very active and there are many users, so it would be safe to include it in your production workflows.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s