[Solved] XlsxFormatProvider.Export sometimes corrupts target excel file since at least Telerik Q4 2025

1 Answer 23 Views
General Discussions
ClausDC
Top achievements
Rank 1
Iron
Iron
Iron
ClausDC asked on 10 Mar 2026, 10:21 AM | edited on 10 Mar 2026, 10:24 AM

As the subject says, when using

  using (Stream output = new FileStream(excelFileInfo.FullName, FileMode.OpenOrCreate, FileAccess.Write))
  {
      new XlsxFormatProvider().Export(workbook, output);
  }

Sometimes the resulting Excel file is corrupted and cannot be imported again. I couldn't figure out a pattern so far because it is not with every export of changes in the excel workbook. This issue appears at least since Telerik Version 2025.4.1321.80

The issue seems not to appear in Telerik Version 2024.2.426.70 or earlier.

When the file is corrupted, opening in MS Excel shows the repair dialog.

Attempting to import it via Telerik XlsxFormatProvider throws an Exception:

System.IO.InvalidDataException: Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory.

It seems to be some issue with the internal Zip File handling.

Stack Trace:

   at System.IO.Compression.ZipArchive.ReadCentralDirectoryPostOuterLoopWork(Int64 numberOfEntries)
   at System.IO.Compression.ZipArchive.ReadCentralDirectory()
   at System.IO.Compression.ZipArchive.get_Entries()
   at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.GetZipEntries(ZipArchive archive)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.Import(Stream input, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider.ImportOverride(Stream input, CancellationToken cancellationToken)
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.WorkbookFormatProviderBase.Import(Stream input, Nullable`1 timeout)

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Mar 2026, 12:44 PM

Hello, Claus,

I am sorry to hear that you are facing any difficulties with the SpreadProcessing library when exporting XLSX documents.

Based on your description, the XlsxFormatProvider.Export method sometimes produces corrupted Excel files when using FileMode.OpenOrCreate. The corruption is confirmed by Excel's repair dialog and the exception thrown during import, specifically:

System.IO.InvalidDataException: Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory.

This points to a ZIP structure issue, as XLSX files are ZIP archives internally.

When you use FileMode.OpenOrCreate, if the file already exists, the stream is not truncated. This can leave old data at the end of the file, resulting in ZIP archive corruption. This is why the exported file sometimes cannot be opened or imported. Switch to FileMode.Create to ensure the file is always overwritten and truncated, preventing leftover data from previous exports:
Telerik.Windows.Documents.Spreadsheet.Model.Workbook workbook = new Telerik.Windows.Documents.Spreadsheet.Model.Workbook();
     workbook.Worksheets.Add();
     string fileName = "SampleFile.xlsx";

     Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider formatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider();

     using (Stream output = new FileStream(fileName, FileMode.Create))
     {
         formatProvider.Export(workbook, output, TimeSpan.FromSeconds(10));
     }

This change should resolve the corruption issue.

However, without replicating the issue locally and having a sample document to test with, we can make only conjectures what causes this undesired behavior. Hence, if the above suggestion doesn't impact the behavior on your end, it would be greatly appreciated if you can provide a sample runnable project demonstrating the issue you are facing. Thus, we would be able to make an adequate analysis of the precise case and provide further assistance. Thank you in advance.

I hope you find this information helpful. Please, let me know if there is anything else I can assist you with.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
General Discussions
Asked by
ClausDC
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or