Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FlexCel created corrupted xlsx file

I use the FlexCel library to create an Excel report in the .xlsx format.

When creating a file in .xls format - everything works fine.

When I try to create a file in the .xlsx format, the file is created, but when I open it by Excel, I get an error that the file is corrupt and can not be opened. And the file has the size in half from .xls.

If someone has encountered a similar problem or knows a solution, I will be very grateful for the answer.


Edit: My code

    var templateFilePath = "D:/template.xlsx";
    var newReportPath = "D:/report.xlsx";
    using (var fr = new FlexCelReport(true))
    {
        fr.AddTable("SOReport", dataTable);
        fr.Run(
            templateFilePath,
            newReportPath
        );
    }
like image 641
Wizard Avatar asked Jul 28 '26 21:07

Wizard


1 Answers

I had the same problem with export in xlsx format with old versions of FlexCel.

Currently I've tested it on FlexCel v5.5.1.0 and there is interesting behaviour:
If I use Excel 2016 or above to create xlsx templates - then I get "file is corrupted" error while trying to open exported xlsx file.

But if I use Excel 2013 or below to create xlsx templates - then I can open it perfectly without errors.

Also mention that if you open xlsx template created by Excel 2013 or below in Excel 2016 or above and save it - you can't restore it to working state in the future. Template will lost for you.

Too late but I hope this can help you.


P.S. Probably, FlexCel team (TMS Software) fixed it starting with v6.7.16.0 version of FlexCel. I think so because documentation said something similar: https://www.tmssoftware.com/site/flexcelnet.asp?s=history
Points like Improved : Improved compatibility with invalid xls and xlsx files
But I can't argue that.

like image 106
picolino Avatar answered Jul 30 '26 16:07

picolino