Free Support Forum - aspose.com

Convert xls to xlsx from visio file (Old version to latest version)

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

@msindia

Would you kindly share a screenshot of the issue that you are mentioning. We have tested the scenario in our environment using Aspose.Diagram for .NET 20.6 and noticed another issue that excel object was not showing in the output VSDX. Would you kindly share your feedback so that we can further proceed accordingly.

@msindia

We have logged an issue as DIAGRAMNET-51859 in our issue tracking system for Excel object becoming corrupted in output diagram. We will investigate it further and keep you informed about its rectification status. Please spare us some time.

We are sorry for the inconvenience.