After playing around with text boxes created in Word documents, I ended up feeling that the current situation around markup compatibility in relation to text boxes is rather confusing. Here is what
I've found:
* Create a blank document in Word2007 and draw a text box [Insert (Ribbon tab) -> Shapes (Illustrations group) -> Text Box]. Word 2007 will use DocumentFormat.OpenXml.Vml.TextBox to wrap the
text box created. See [1] later for XML code.
* Do the same in Word2010 and it will create markup compatibility content to use the newer <w:drawing> graphic frame and the older <w:pict> frame as fallback. See [2] later for XML code.
In the <w:drawing> version, the OpenXML elements around the text box are Office2010 specific , including the use of DocumentFormat.OpenXml.Office2010.Word.DrawingShape.WordprocessingShape (<wps:wsp>) and DocumentFormat.OpenXml.Office2010.Word.DrawingShape.TextBoxInfo2
(<wps:txbx>).
* Do the same in Word2013 and it will create markup compatibility content similar to Word 2010, perhaps with the exception of not creating certain Office2010 specific elements (<wp14:sizeRelH>
etc). See [3] later for XML code.
Now I tried using OpenXML SDK 2.5 to open the documents created above with specific markup compatibility settings, here are the results:
Word2007 doc with text box
Nothing exciting here, will always load <w:pict> version with VML text box since that's the only version available.
Word2010 doc with text box
MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2007
Loads the <w:pict> (fallback) version.
MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2010
Loads the <w:drawing> version.
MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2013
Loads the <w:pict> (fallback) version. Why??
Word2013 doc with text box
MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2007
Loads the <w:pict> (fallback) version.
MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2010
Loads the <w:drawing> version.
MarkupCompatibilityProcessSettings.TargetFileFormatVersions = FileFormatVersions.Office2013
Loads the <w:pict> (fallback) version. Again, why??
Based on these results, I ended up with a few (rather nitpicking) discussion questions:
Why is the fallback version selected when I set TargetFileFormatVersions to Office2013 and open a Word2010 or Word2013 document? I would have thought having TargetFileFormatVersions set to Office2013
is inclusive of Office2010?
The ISO 29500-1 3rd edition spec (released in 2012) suggests DrawingML is the newer format to replace any uses of VML, but it seems the realities are different because the Word2013 document does not
fully use DrawingML for text boxes (and the DrawingML code that it does use is Office2010 specific), it still includes VML text box code as the fallback case. So does this mean that while VML should be deprecated, it hasn't taken place in Word2013?
Why is TargetFileFormatVersions in the plural and FileFormatVersions a FlagsAttribute, when doing a FileFormatVersions.Office2010 | FileFormatVersions.Office2013 actually results in an exception?
The OpenXML SDK Class Library Reference (http://msdn.microsoft.com/en-us/library/office/gg278315%28v=office.15%29.aspx) includes Office2010 specific namespace (DocumentFormat.OpenXml.Office2010) and
Office2013 specific namespace (DocumentFormat.OpenXml.Office15), but why is there no link to view the classes within the Office2013 namespace? Does this imply we (non-Microsoft developers) should not know about those classes? Then what about Office2010 specific
classes? If we should not use Office2013 and Office2010 specific classes, does that mean we should stick with VML? So just forget about what the spec says (because it is more of an academic exercise)?
Now here is a more practical question:
I want to write code to process a Word2013 document with text boxes. I'm working off the ISO 29500-1 3rd edition spec right now and I don't particularly want to spend time understanding VML if I don't
have to. But since opening the Word2013 file with OpenXML SDK and TargetFileFormatVersions set to Office2013 will result in the fallback VML version been used, does it mean that I should know about VMLand not worry about Microsoft dropping VML use in Word for the foreseeable future?
[1]
<w:p><w:r><w:pict><v:shapetype... >
...</v:shapetype><v:shape... ><v:textbox><w:txbxContent><w:p>... </w:p></w:txbxContent></v:textbox></v:shape></w:pict></w:r></w:p>
[2]
<w:p ><w:r><mc:AlternateContent><mc:Choice Requires="wps"><w:drawing><wp:anchor ><wp:simplePos x="0" y="0" /><wp:extent cx="3218400" cy="2059200" /><wp:docPr id="1" name="Text Box 1" /><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"><wps:wsp><wps:cNvSpPr txBox="1" /><wps:spPr>...</wps:spPr><wps:txbx><w:txbxContent><w:p>...</w:p></w:txbxContent></wps:txbx></wps:wsp></a:graphicData></a:graphic><wp14:sizeRelH relativeFrom="margin"><wp14:pctWidth>0</wp14:pctWidth></wp14:sizeRelH><wp14:sizeRelV relativeFrom="margin"><wp14:pctHeight>0</wp14:pctHeight></wp14:sizeRelV></wp:anchor></w:drawing></mc:Choice><mc:Fallback><w:pict>
(same as Word2007 content)</w:pict></mc:Fallback></mc:AlternateContent></w:r></w:p>
[3]
<mc:AlternateContent><mc:Choice Requires="wps"><w:drawing><wp:anchor><wp:simplePos x="0" y="0" /><wp:extent cx="3419475" cy="1114425" /><wp:docPr id="1" name="Text Box 1" /><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"><wps:wsp><wps:cNvSpPr txBox="1" /><wps:spPr>...</wps:spPr><wps:txbx><w:txbxContent><w:p>...</w:p></w:txbxContent></wps:txbx></wps:wsp></a:graphicData></a:graphic></wp:anchor></w:drawing></mc:Choice><mc:Fallback><w:pict>(same as Word2007 content)</w:pict></mc:Fallback></mc:AlternateContent>