2

I am a complete beginner with DrawingML. I am trying to figure out if I can define a shape using the language, save it in some format and import it directly into a drawing canvas inside a Word document.

The motivation behind this is to enable users save an on-line generated graph as a file and import it into a canvas inside a Word document. The graph nodes should be connected so that when a node is dragged it will also mode the connector. My understanding is that it is possible to create such drawings using DrawingML but am not sure how to import such drawing into a document.

David
  • 3,075
  • 3
  • 26
  • 36
  • Its possible. Is the import to happen while the document is open in Word, or will you add it to a docx file (without Word necessarily even being installed on the system)? What is your preferred programming language? – JasonPlutext Feb 19 '14 at 01:50
  • The import is to happen while the document is open in Word. Java would be good. – David Feb 19 '14 at 10:42

1 Answers1

1

You can create a Flat OPC XML file containing your DrawingML.

Then you add it to your docx open in Word. You can do that using VBA (a macro), or VSTO (a Word Add-In).

For more on Flat OPC XML, see http://blogs.msdn.com/b/ericwhite/archive/2008/09/29/the-flat-opc-format.aspx

You can add the Flat OPC XML using Range.InsertXml. See also Can I use VSTO instead of Open XML to manipulate altChunk features?

VSTO is a .NET thing. Generally you'd code in C# or VB.NET. You can use Microsoft's Open XML SDK as necessary. So Java doesn't usually have a role. Having said that, I do know of companies that are committed to Java server side and using docx4j there, and want to use the same technology client side, and so use docx4j IKVM'd as a DLL. In this context, that could be how you create your DrawingML (ie using JAXB), then produce the Flat OPC XML.

Community
  • 1
  • 1
JasonPlutext
  • 15,352
  • 4
  • 44
  • 84
  • Thank you for the advice. This however looks more complicated than what I hoped for. Is there no way of converting my DrawingML into a Windows Enhance Metafile (or other format supported by Word's Insert/Pictures function? – David Feb 20 '14 at 22:04
  • Powerpoint exposes a "save as picture" which lets you save it as PNG, EMF, WMF. In Word, you can do the same thing with copy/paste: http://office.microsoft.com/en-au/word-help/save-a-picture-as-a-jpg-gif-or-png-HA010354818.aspx So, you could write a macro to open a docx containing just your drawing, copy the drawing, and paste-special it into your existing docx. – JasonPlutext Feb 20 '14 at 22:19
  • I guess you achieve your objective by opening a docx containing just your drawing, then copy/paste it into your target docx (ie you may as well retain the DrawingML). – JasonPlutext Feb 20 '14 at 23:55
  • Why didn't I think of that earlier?! Thanks JasonPlutext! – David Feb 21 '14 at 15:41