I have some code that creates a document to be viewed in MS Word. Some XML is run through XSLT, then added into the OpenXML document. The resulting document looks fine in Word 2010, but won't open in Word 2007, which I need to be able to support. How can I create a valid Word 2007 document?
With Open XML Format SDK 2.0 (version 2.0.5022.0)
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
...
using (WordprocessingDocument package = WordprocessingDocument.Create(outputPath, WordprocessingDocumentType.Document))
{
package.AddMainDocumentPart();
MainDocumentPart mainPart = package.MainDocumentPart;
mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document();
// code ... XML translation and append to document
package.MainDocumentPart.Document.Save();
}
.
This post has some useful information:
There are differences between Word 2010 and Word 2007, and they adhere to different versions of the OOXML standard. It is quite possible that you have included content that works in Word 2010, but that Word 2007 can't handle. You don't provide any helpful information to say what that may be, but when Word 2010 creates documents it uses "AlternateContent" tags to provide different versions of the xml for different versions of Word and you may have to do the same, or limit yourself to Word 2007-compatible content.
How would I know what "Word 2007-compatible content" is in advance?