Hi,
We have visio file and that file have ‘.xls’ file. So we collect the ‘.xls’ shapes then save to ‘.xlsx’. FInally save the Visio file, Still the excel shown ‘.xls’ format.
Input: Visio Excel.zip (50.1 KB)
Code:
public void TestVisioExcel()
{
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
FileFormatInfo info = FileFormatUtil.DetectFileFormat(Ole_stream);
if(info.LoadFormat == LoadFormat.Xlsx||info.LoadFormat== LoadFormat.Excel97To2003)
{
// Modify an OLE object
Workbook workbook = new Workbook(new MemoryStream(OLE_Shape.ForeignData.Value));
MemoryStream outStream = new MemoryStream();
workbook.Save(outStream, SaveFormat.Xlsx);
OLE_Shape.ForeignData.ObjectData = outStream.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