How to insert Visio file into DOCX

@alexey.noskov thanks for your explanation. If it is, how can i use aspose.words to meet this requirement. I think it is a common funcationality in MS Office when inserting visio diagram.

@space_chang To achieve what you need you should render your Visio diagram to metafile image and use this image as OLE object presentation upon inserting it into the document.

@alexey.noskov thanks for your guide and i will follow it to try the solution.

1 Like

@alexey.noskov I tried your aspose.diagram to convert vsdx into emf. and it can be inerted into docx smoothly. but the figure size(width&height) is so large. how to adapt the presentation figure to the actual size of docx page?

@space_chang You can change size of the insert OLE object shape. For example see the following simple code:

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

with open("C:\\Temp\\src.emf", "rb") as presentation_stream :
    ole_shape = builder.insert_ole_object("C:\\Temp\\src.docx", False, False, presentation_stream)
    # change OLE object shape size as required
    # by default lock aspect ratio option is enabled so the shape is resized proportionaly.
    # you can disable this option to chnage width and height independently
    ole_shape.aspect_ratio_locked = False
    ole_shape.width = 100
    ole_shape.height = 100

doc.save("C:\\Temp\\out.docx")

@alexey.noskov This code works well to present the proper figure size after inserting the visio file into DOCX. but it cannot fix the size consistantly. that is to say the figure size will change to be large after i edit the visio diagram(Open DOCX->right click on the visio figure->Open) and save it.

@space_chang I am afraid further processing the document is out of Aspose.Words control. When you edit Visio object and save it MS Word updates the presentation image, which is provided by the consumer application used to edit the object.

@alexey.noskov Maybe~~~, but i tried it using MS word. when i insert the visio diagram into docx and adjust the visio figure size to be proper, i open the visio file from docx to edit it and save it. the size of visio figure is still fixed. I’am not sure what is the difference between MS word and aspose.words for that.

@space_chang Could you please attach your documents produced by Aspose.Words and MS Word here for our reference? We will check the documents and provide you more information.

@alexey.noskov below are the documents you want. the emf used for ASPOSE.docx is produced by MS visio from the corresponding visio file instead of aspose.diagram. please have a check!

MS.docx (62.6 KB)
ASPOSE.docx (61.6 KB)

@space_chang
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26907

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@alexey.noskov Thanks for your confirmation. I think it is related to some DOCX settings.
Is there alternative solution to fix this issue by using aspose.word to change corresponding setting before you fix it?

@space_chang I compared internal OLE object representation in MS Word and Aspose.Words created documents and they look almost the same. So, unfortunately, I did not manage to find what causes this behavior. Our development team will analyze the issue deeper. We will keep you update and let you know once the issue is resolved or we have more information for you.

@alexey.noskov I analyzed the raw DOCX data and found below difference may cause the above issue.


I’m not experienced in DOCX meta data, so could you help to verify it and provide potential solution?

@space_chang There are w:dxaOrig and w:dyaOrig attributes that Aspose.Words do not write. They seem to be optional. Unfortunately, our development team have not analyzed the issue yet. So currently we do not have any additional information we can share. Please accept our apologies for your inconvenience.

2 posts were merged into an existing topic: 怎么查询docx表格内容以及合并规则

@alexey.noskov That’s OK. do you know how to determine the value of dxaOrig and dyaOrig based on EMF figure or Visio diagram. If i know the method, i think i can use aspose to search for the object node and set the values.

@space_chang There is no way to set dxaOrig and dyaOrig values using Aspose.Words. These values are not written by Aspose.Words.

@alexey.noskov Thanks for your explanation. In these days, I analyzed the data further and have a puzzle about the differences to size of EMF figure between MS and ASPOSE when inserting same visio diagram into DOCX like below:


MS.docx (45.5 KB)
ASPOSE.docx (36.5 KB)
MS.docx: inerting the visio diagram by MS office directly.
ASPOSE.docx:generate the EMF figure by aspose.diagram, then using it as the presentation figure to insert the visio diagram into DOCX without setting the figure size(width&height).

@space_chang Most likely the difference is caused by the difference in the presentation image size generated by Aspose.Diagram and MS Word.