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.

Parents
No Data
Reply
  • 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

Children
No Data