

And bad if your want your “first” Row class to be on the 3rd row instead. In this case, Excel tries to guess which row it is, and places the first Row class content into the first row on the spreadsheet. In Brian’s code, notice that the RowIndex property of the Row class is not assigned.

Google doc merge cells have borders overlap code#
In this case, think of the SDK as getting in the way of making your code run faster. Use the OpenXmlWriter to write that property, because that property is eventually an XML attribute anyway. As in you don’t mix SDK class/property usage code with OpenXmlWriter code.īasically, if there’s an SDK class property you want to set, don’t assign to that property in code. When you use the OpenXmlWriter, it works best if it’s used all the way. The more subtle (and possibly more crucial) information that’s missing is of attributes. If you have something like () mixed with the use of OpenXmlWriter, it’s not going to work. Work with the DOM structure using the SDK, which means snail-pace if you’re writing many cells.After he’s done reading, he deletes the old WorksheetPart. This is why in Brian’s code, he reads in the existing worksheet and writes the content into a new worksheet, thus using a new WorksheetPart that’s “attached” to the WorkbookPart. So you can’t just use the OpenXmlWriter to write the XML stuff into an existing WorksheetPart, because any changes you made will be ignored. This means there’s a corresponding WorksheetPart (to your Worksheet class), and this WorksheetPart already has the XML structure (and more importantly, a DOM structure). If you’re working with an existing worksheet, there’s already an existing XML structure in place. So instead of using the SDK classes to form the “XML” parts, we use the OpenXmlWriter to directly write out the XML. The SDK offers classes and properties that we’re familiar with, but underneath it all, an Open XML spreadsheet’s internal structure are XML files zipped together. The reason for this is that OpenXmlWriter is essentially writing out XML tags. OpenXmlWriter works best for creating new thingsįor the purposes of explanation, we’ll assume the “new thing” is a new worksheet, although OpenXmlWriter can be used to write any Open XML SDK part (such as WorkbookPart). There are a couple of things that weren’t mentioned though. Brian Jones already wrote something on using the OpenXmlWriter with the Open XML SDK to write large Excel files.
