admin管理员组

文章数量:1279016

I have a .NET Framework 4.8, C# application. I'm using IronXL.Excel 2025.2.5 to read and export data to an xls file (that's an old Excel 97-2003 file; unfortunately this cannot be changed to a modern Excel version; I have no control over this). I set up a very short test script to read the file, make a change and save it. It worked fine. However, when I then open the file I get the error "We found a problem..." (see full error below). It still allows me to open the file and if I save it, the error goes away. However, this error is going to cause confusion with my client. Is there anyway to save the changes without getting this error message?

I've tried other nuget packages like ClosedXML and EPPlus, but none of them seemed to work with xls files. If you have a suggestion that will let me read and write to an xls file, I'm open to using another package.

Here is my code:

    string filePath = @"C:\TEMP\Test.xls";

    WorkBook workBook = WorkBook.Load(filePath);

    WorkSheet worksheet = workBook.WorkSheets[0];

    for (int row = 1; row < 10000; row++)
    {
        string cell = $@"A{row}";
        string cellValue = worksheet[cell].ToString();
        if (cellValue == "")
        {
            worksheet[cell].Value = "New Value Here";
        }
    }

    workBook.Save();

Here is the error message:

本文标签: cHow do I prevent IronXL from corrupting my saved Excel fileStack Overflow