Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Mon Nov 28, 2022 8:00 am

Error in the conversion from a .xml file to .xlsx.

I try to convert some .xls file in .xlsx but for some reasons some files need to be converted from .xls to .xml and THEN .xml to .xlsx. However I have an error in the catch "Invalid syntax for a decimal numeric entity reference" that I am unable to resolve.

My best guess is this is something to do with some characters that 'Spire.xls' can't understand.

BTW I'm using spire.xls

Code: Select all
if (dossiersBD != null && dossiersBD.ChEtat == 1)
                //if (dossiersBD != null)
                {
                    ft.CopyTo(directorypath, true);

                    if (System.IO.Path.GetExtension(Convert.ToString(f.FullName)) == ".xls")
                    {
                        string pathNewFile = System.IO.Path.ChangeExtension(f.FullName, ".xlsx");
                        Workbook workbook = new Workbook();
                        //workbook.Version = ExcelVersion.Version2007;
                        try
                        {
                            workbook.LoadFromFile(ft.FullName);
                        }
                        catch
                        {
                            string pathNewFileExtension = System.IO.Path.ChangeExtension(pathNewFile, ".xml");
                            System.IO.File.Move(f.FullName, pathNewFileExtension);

                            //using (FileStream fileStream = File.OpenRead(pathNewFileExtension))
                            //{
                            //    workbook.LoadFromXml(fileStream);
                            //}

                            workbook.LoadFromXml(pathNewFileExtension);
                            workbook.SaveToFile(pathNewFile, ExcelVersion.Version2010);
                            ft = new FileInfo(pathNewFile);
                           
                        }
                       
                       

                    }


Any idea why i'm getting this error message?

jdabadie
 
Posts: 2
Joined: Mon Nov 28, 2022 7:46 am

Mon Nov 28, 2022 10:26 am

Hello,

Thanks for your inquiry.
Are you using the latest version of Spire.Xls 12.11.3? If not, please update to it and test your issue again. If the issue still exists, please offer the following message, thanks for your assistance in advance.
1) Your input file, you can attach them here or send them via email(support@e-iceblue.com).
2) Application type, such as Console App, .NET Framework 4.8.
3) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Tue Nov 29, 2022 8:48 am

Thank you I sent an email about it.

jdabadie
 
Posts: 2
Joined: Mon Nov 28, 2022 7:46 am

Tue Nov 29, 2022 10:07 am

Hello,

Thanks for your feedback.
According to the message you mentioned, I created a console project with the .NetFramework 4.8 to test your issue, however, I d’dn't reproduce your issue. I put my test code below and attached the result xlsx file for your reference.
Code: Select all
if (System.IO.Path.GetExtension(Convert.ToString(@"../../data/101M2133630_22_11_2022.xls")) == ".xls")
            {
                string pathNewFile = System.IO.Path.ChangeExtension(@"../../data/101M2133630_22_11_2022.xls", ".xlsx");
                Workbook workbook = new Workbook();
       
                try
                {
                    workbook.LoadFromFile(pathNewFile);
                }
                catch
                {
                    string pathNewFileExtension = System.IO.Path.ChangeExtension(pathNewFile, ".xml");
                    System.IO.File.Move(@"../../data/101M2133630_22_11_2022.xls", pathNewFileExtension);
                    workbook.LoadFromXml(pathNewFileExtension);
                    workbook.SaveToFile(@"../../output/result.xlsx", ExcelVersion.Version2010);
                   

                }

            }


Sincerely
Abel
E-iceblue support team
Attachments
1111.png
1111.png (118.11 KiB) Viewed 1855 times
result.zip
(11.6 KiB) Downloaded 145 times
User avatar

Abel.He
 
Posts: 860
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.XLS