Hi,
We have visio file and that file have ‘.doc’ file. So we collect the ‘.doc’ shapes then save to ‘.docx’. FInally save the Visio file, Still the documnet shown ‘.doc’ format.
Input: Visio Doc.zip (2.8 MB)
Code:
[TestMethod]
public void TestVisioDocument()
{
using(FileStream _licenseStream = LicenseStream(out License licDiagram, out Aspose.Cells.License licCell))
{
string[] files = Directory.GetFiles(@“C:\Users\input”, “*.vsdx”);
foreach(string file in files)
{
Diagram diagram = new Diagram(file, LoadFileFormat.VSDX);
foreach(Page diagramPage in diagram.Pages)
{
foreach(Shape OLE_Shape in diagramPage.Shapes)
{
if(OLE_Shape.Type == TypeValue.Foreign)
{
if(OLE_Shape.ForeignData.ForeignType != ForeignType.Object) continue;
if(OLE_Shape.ForeignData.ObjectData == null) continue;
Stream Ole_stream = new MemoryStream(OLE_Shape.ForeignData.Value);
// Get format of the OLE file object
Aspose.Words.FileFormatInfo info = Aspose.Words.FileFormatUtil.DetectFileFormat(Ole_stream);
if(info.LoadFormat == Aspose.Words.LoadFormat.Doc || info.LoadFormat == Aspose.Words.LoadFormat.Docx)
{
// Modify an OLE object
Document doc = new Document(new MemoryStream(OLE_Shape.ForeignData.Value));
Aspose.Words.Saving.OoxmlSaveOptions options = new Aspose.Words.Saving.OoxmlSaveOptions();
options.SaveFormat = Aspose.Words.SaveFormat.Docx;
using(MemoryStream stream = new MemoryStream())
{
doc.Save(stream, options);
OLE_Shape.ForeignData.Value = stream.ToArray();
}
}
}
}
// Save Visio diagram
diagram.Save($"C:\\UsersDirectExcel\\{Path.GetFileNameWithoutExtension(file)}out{DateTime.Now.ToString("yyyyMMddHHmmss")}.vsdx", SaveFileFormat.VSDX);
}
}
}
}
Waiting for your support and reply.
Thanks