wordpress hit counter
Inserting Visio XML into Word document - DrawingML - Formats - OpenXML Developer

Inserting Visio XML into Word document

Formats

Discussions about working with different Open XML Formats

Inserting Visio XML into Word document

  • rated by 0 users
  • This post has 7 Replies |
  • 0 Followers
  • I'd like to be able to insert a Visio diagram into a Word document using XML.

    That is, I'd like to take a Visio diagram that's been saved in DataDiagrammingML and insert that text into a Word document which is in WordProcessingML format.

    I'm looking for any way to automatically insert a Visio drawing into a Word document without human intervention with Word menus, mouse clicks, etc.

    Any suggestions?

    Thanks, Mike

     

  • Hi,

    When you will insert a visio diagram in a word document it will be stored as an ole object.

    So if you want to insert a visio file programmatically you can follow the below mentioned steps:

    1.Open your package.

    2.Get the main document part.

    3.In your main document part insert the following code.

      <w:object w:dxaOrig="1800" w:dyaOrig="765">
              <v:shape id="_x0000_i1025" type="#_x0000_t75" style="width:90pt;height:38.25pt" o:ole="">
                <v:imagedata r:id="rId6" o:title=""/>
              </v:shape>
              <o:OLEObject Type="Embed" ProgID="Package" ShapeID="_x0000_i1025" DrawAspect="Content" ObjectID="_1265609281"    

    r:id="rId5"/>
            </w:object>
          </w:r>

    4.rId6 will render to the media part.So create the media part and relationship.
     
    "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.wmf"/>


    rId5 will render to the embeddings part.so create the embeddings part and relationship.

    "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject" Target="embeddings/oleObject1.bin"/>

    5.Save the document part.

    6.close the package.


    Mallika

  • Thanks for the information.  I'll give it a try.

    Which of the constants in your example are fixed for any Visio object, and which need to be redone for another object?

    Which of the ID values need to be changed?  Does it matter what their values are?

    Any other precautions?

    Thanks again, Mike

     

  • Hi,

    1.oleObject1.bin file is specific for every ole object.So you have to take the specific oleObject1.bin file
      for inserting visio file and this is most important.

    2.For image representation of your object you have to change media/image1.wmf as you want to change.

    3.ProgID and ObjectID attributes should must be present.
      But you can give any value,even can keep it blank.

    4.ShapeID attribute should be present and it can't be null.
      The ShapeID value should be same in v:shape and o:OLEObject elements.


    Mallika

  • This has all opened a "can of worms" for me.  I've been using XML and WordML for a little while, but this imagedata and relationship stuff is all new.

    (1) Wouldn't this be simpler:
    <w:p>
        <w:r>
            <w:pict>
                <v:shape id="myShape2" type="#_x0000_t75" style="width:7.0in; height:4.67in">
                    <v:imagedata src="mypicture.wmf" o:title="my title"/>
                </v:shape>
            </w:pict>
        </w:r>
    </w:p>

    This has the drawback that the picture must be available when the Word document is opened, since the picture is not embedded in the Word document.
    So the picture file and the document file must be copied together if the directory location changes.

    (2) I tried several things with the relationships stuff, and none of it worked.  As I said, this is all new to me, so I'm sure I messed up something.  I did create a "_rels" subdirectory and put document.xml.rels in that directory.  The file had the relationship XML elements.  The "rId6" and "rId5" didn't seem to work, although that may have been because my .rels file wasn't correct.

    (3) By "Open your package", what do you mean?  This is new, also.

    (4) How do I create the embeddings part?  That is, how do I create the oleObject1.bin file?  And where does it go?  What is distinct about this file compared with the mypicture.wmf file?  Why 2 files for one picture?

    (5) Doesn't this also have the disadvantage of not being embedded in the Word document?  So if the document.xml file moves to another directory, the Visio file must also be moved.

    (6) Are there good references on the Internet for the elements and attribute, say for w:object, w:dxaOrig, w:dyaOrig, v:shape id, o:OLEObject ProgID, o:title, etc.?

    (7) I've been using Oxygen 9.1 on Windows XP for my XML work.

    I know I have lots of questions, but I couldn't find good explanations or examples on the Internet.

    Thanks for more help.  Feel free to contact me via emal.

    -- Mike

  • Hi,

    When you will insert a visio file it will be stored as ole object(an object that is embeded in the document),not as a   picture.

      <v:shape id="_x0000_i1025" type="#_x0000_t75" style="width:90pt;height:38.25pt" o:ole="">
                <v:imagedata r:id="rId6" o:title=""/>
              </v:shape>
     
      The above mentioned portion is only used for image representation of your object(visio file).
      If you ommit this then also you will get your object embeded,but will not get the picture for the object.

      You can reffer ECMA specification that is ECMA-376 for office open xml file formats to get the details of the
       elements.

    If you want to create xml files programmatically you have to either use system.IO.packaging or open xml SDK.

    So,please explain clearly,what is your ultimate goal?

    Mallika
  • My goal is to us XSL to transform data into a Word document in XML format.  I just want to use XSL transformations without the use of C++, C#, Java, scripting, etc.

    I wanted to include drawings in my Word document.  The information about relationships, etc., was new to me and I could not make it work.

    For now, I'm using <w:binData> and <v:imagedata> elements with Base64 encoded data representing the drawings I wanted to include.  This way I can embed the data into the WordML file for my Word document and not depend on external files.

    So, for now I'm set with this mechanism.

    Thanks for your suggestions.

    - -Mike

  • There are a few templates available on the Visio toolbox website.
    You can have a look there, they give great Visio Diagrams with examples.

Page 1 of 1 (8 items)