Exploring Table Markup in Open XML SpreadsheetML
Return to the SpreadsheetML Screen-Cast SeriesTables are a convenient and useful feature of Open XML SpreadsheetML. This post explores table markup, and links to a screen-cast that shows how to create a table programmatically.
The table feature has been part of Excel for some time; most users are familiar with tables. When you convert cells to a table in a spreadsheet, instead of seeing ordinary cells, you see a block of cells that have interesting characteristics. You can sort the table by clicking on the down-arrow in the column heading. You can insert rows in the table, and the rows become part of that table automatically. The banded colors make it easy to read.
It is pretty easy to create a table in Open XML SpreadsheetML. If you have some ordinary cells that have the data that you want to use to create the table, you need to do the following:
- In the worksheet, you need to add a x:tableParts element that specifies a relationship to a table part.
<x:tableParts count=”1″>
<x:tablePart r:id=”rId1″ />
</x:tableParts> - You need to create a table part that has the appropriate elements and attributes to define the table.
- If the table has special formatting, you need to define the formatting in the x:dxfs element in the Styles part.
The following screen-cast walks through the process of discovering the markup necessary to convert some cells to a table, and shows creating a small Open XML SDK example to convert some ordinary cells into a table.
Download: Example that contains the finished result of the screen-cast.