Posts

Showing posts from December, 2011

New version of WordXML document using OpenXML SDK 2.0 with bold, color and font size formatting

Image
  I first dabbled with the OpenXML SDK 2.0 in January 2011 . At that time, there was a problem which I could not solve: specifying different font sizes, font colors and bolding effects for different words on the same line. I managed to achieve different formatting effects for sentences on different lines, but never managed to get it working if the words were on the same line. Today, I finally figured out how to do it, and scroll down if you are interested to look at the code. Oh, and do remember to add in the reference for OpenXML SDK and add the imports. A screenshot of how the generated Word document looks like: using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Wordprocessing; public void GenerateWord(){ WordprocessingDocument doc = WordprocessingDocument.Create(filename, WordprocessingDocumentType.Document); MainDocumentPart mainPart = doc.AddMainDocumentPart(); mainPart.Document = new Do...