Link to home
Start Free TrialLog in
Avatar of Skale
Skale

asked on

Saving Excel workbook even the tool collapsed or thrown an error in C#

I've code like below;

            if (CreateExcelFile(output_file))
            {
                var workbook = new ClosedXML.Excel.XLWorkbook(output_file);

// Additional to-do will list in here

                GenTplParams(workbook); //This writes something in excel

                workbook.SaveAs(output_file);
            }
        }

Open in new window



GenTplParams() is writing some values on that excel file from 3rd party tool and sometimes it can crash or thrown an error while processing and when i'm getting at the end a blank excel file.

But i'd like to get the file with already written values until the crash/error occurs also it'll give me an advantage to find out which value gives an error. I can easily read the excel file and check the last value and figure out the next value has a problem.

P.S. values are getting from 3rd party softwares COM objects.

Any help makes me glad. Thank you.
Avatar of j2nku
j2nku
Flag of Estonia image

Hi Hakan,

I would rather debug the code in Visual Studio to identify problematic areas. Or look into the GenTplParams function and see if try-catch has been correctly used.

BR,
J.
ASKER CERTIFIED SOLUTION
Avatar of Eduard Ghergu
Eduard Ghergu
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial