Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
165
Excel file corrupted after load/save
posted

Hi, 

In my application, I have to load and save many times excel files.

Some of them become corrupted after multiple saves.

I tried with a sample project to load and save multiple times and for an excel document, it become corrupted after 4 load/save.

Here is my sample code : 

using System;
using Infragistics.Documents.Excel;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            const string filePath = "D:\\Template - ErrorAfter4Saves.xlsx";

            for (var i = 0; i < 4; i++)
            {
                var workbook = Workbook.Load(filePath);
                workbook.Save(filePath);
            }

            Console.WriteLine("File Corrupted !");
            Console.ReadLine();
        }
    }
}

And here is the excel file : 

3225.Template - ErrorAfter4Saves.xlsx

If i try to open it after running my sample code, it will be corrupted.

I don't know why after 4 times.

Thank You for your answers.

  • 31690
    Offline posted

    Hello Infragistics User,

    I have been investigating into this behavior you are reporting, and I have put together a sample project using the code that you have provided as well as the Excel file that you have provided, and after saving and loading four times, I am seeing an error on load of the Excel file, but it isn't really a full "corruption" on my end.

    When trying to load the Excel file, I am receiving a message that reads:

    "We found a problem with some content in <filename>. Do you want us to recover as much as we can?"

    If I click "Yes" on this dialog, it appears that everything is restored normally, and so it does appear that there is an issue when saving the Workbook multiple times, although I cannot be sure if this completely matches the behavior you are seeing. Are you seeing the same behavior in this case, or are you seeing a more "complete corruption" of the Excel file, in that you are completely unable to reopen it after saving?

    It also may be helpful if you can please provide the Infragistics for Windows Forms version that you are using. My tests were made against specific version 17.2.20172.2006 in Infragistics for Windows Forms 2017 Volume 2. Is this the same version you are using? If not, would it be possible for you to please provide the version you are using?

    Please let me know if you have any other questions or concerns on this matter.

  • 0
    Offline posted

    Hi Kevin,

    I am glad to know that you were able to find out the root cause of the problem and fixed the file which had wrong formulas.

    Although, I have experienced this issue myself and was not able to find out the specific file where the formulas were wrong due to multiple files and large database

    Here are the work around we can try in such cases:

    1) If your Excel spreadsheet contains valuable data you can Make the Excel File ‘Read-only’:

    • In Excel, click File from the main menu.
    • In the screen that appears, select Save for new document or Save As for previously saved document.
    • From the ‘Save As’ dialog box, click Tools > General Options.
    • Click on the ‘read-only’ checkbox to make the document read-only, and then click OK.
    • Open a new and blank '.xlsx' file and copy everything from the corrupt Excel file to this new file. Save this file and try to open it again.

    2) You can also Install Visual Basic Component

    • Navigate to Control Panel > Programs > select Microsoft Office 2010.
    • Click Change, and then select Add or Remove Programs.
    • Next, click the 'plus' sign provided next to Office Shared Features. 
    • Click Visual Basic for Applications. After that, right-click and choose Run from My Computer, and hit the Continue button.
    • Reboot your system when this process finishes.
    • Now check if the issue has been resolved or not.

    3) You can get help using the third party software solely created for Data recovery of corrupted/ partially corrupted Excel files. Here is a tool which I have personally used to repair my corrupted excel file : https://www.stellarinfo.com/repair-excel-file.php