Posts Tagged ‘Office 2007’

Dealing With Table Borders In OOXML

April 5, 2010

Formatting tables in a document programmatically can be a very complex task.  This is the major reason which we start our document generation projects with templates instead of building components in a document by hand.

Borders are on aspect of a table that you may want to fomat.  Borders are used to make certain content in a table stand out.  If you need to conditionally set and remove borders there is something that you need to be aware of.  Even in OOXML you have the concepts of styles, inheriting styles and overriding styles.

When Word defines a table it will reference a global style such as “TableGrid”.  This style will include the borders for the table.  Specifically the InsideHorizontalBorder and InsideVerticalBorder define the borders for the cells.  These can be overridden by the TableCellBorders collection of a particular cell.  Adding a double right border on a cell is as easy as the couple of lines of code below.

wordprocessing.TableCellBorders borders = new wordprocessing.TableCellBorders();

borders.RightBorder = new RightBorder(){Val = BorderValues.Double, Color = "000000", ThemeColor = ThemeColorValues.Text1, Size = (UInt32Value)4U, Space = (UInt32Value)0U };

cell.TableCellProperties.Append(borders);

If I want to revert back to the table’s style for cell borders I simply need to remove all children from the TableCellBorders collection.  It is like removing a class identifier from a TD tag in HTML.  The style in the parent object takes back over.

With the knowledge of how the borders work you can take the concept and apply it to other effects of styles.

The Challenges of Inconsistent Implementation and Office Document Generation

January 29, 2010

I have spent the last several months developing solutions with Office 2007 and the Office Open XML SDK 2.  Our client has requirements that cross the suite from PowerPoint Presentations to Word Documents.  The Open XML standard which define the structure of these documents is very powerful.  My biggest frustration is the lack of consistent capabilities between the products. 

Since we are doing document generation based on templates it is very important we that the code can consistently identify any part of a document, whether that is a section of text, a chart, a table or an image.  While Word 2007 has Content Controls and Custom XML (2007 only) which can be used for marking up a document, similar features are not available in PowerPoint.  This is a major issue for us since the majority of our templated work is in PowerPoint.

A key to a successful solution for me is that a markup needs to be consistent in the way it is implemented in all of the Office applications.  It should also have a way that an end user can add a tag to a document without the risk of it being mislabeled because of human error.  This is one of the drawbacks of Content Controls.  Another thing that makes CustomXml more attractive is that you can use just one type of control to encapsulate content (more on Content Controls versus CustomXml in the next few days).  There are a variety of content controls that are tightly typed.  In other situations this may be a plus, but if anything the developer should be able to define the type of objects used for tagging.

Further, the fact that something as simple as a Text object being in a different namespace even within the same document type means that we have to write duplicate code for dealing with text in charts, document paragraphs and embedded spreadsheets.  If I were to design it, this shared functionality would be abstracted to its own namespace.  I want to be able to write clean, reusable code.

Ultimately the teams within the Office suite need to start working together the way that the language teams have begun to do within Visual Studio.  The same tagging tools should be available in Word, PowerPoint, Excel and OneNote and they should be represented the same in the XML that is rendered.