Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 0x800A03EC when opening with Excel.Application after saving with NPOI #1308

Closed
1 of 5 tasks
JeanPhilippeLux opened this issue Apr 4, 2024 · 5 comments
Closed
1 of 5 tasks

Comments

@JeanPhilippeLux
Copy link

NPOI Version 2.7.0

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Upload the Excel File

Reproduce Steps

I open a file with formulas in it. I change the value of 2 cells and after I call XSSFFormulaEvaluator.EvaluateAllFormulaCells(newWorkbook);

after that I open the file with the MS Excel Interop (here is my code)

"Excel.Application excelApp = new();

Excel.Workbook wb = excelApp.Workbooks.Open(fileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);

Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];"

And on the last line the application crash with error code : 0x800A03EC

Issue Description

If I open the file in Excel, Excel says the file is corrupt and he fix it the the message : "remove /xl/calcChain.xml"

I rollback to 2.6.2 and the Excel files are not corrupt anymore.

thank you.

@Bykiev
Copy link
Collaborator

Bykiev commented Apr 4, 2024

Hi, can you please attach original file and corrupted?

@JeanPhilippeLux
Copy link
Author

Oh, sorry.

Here you have the 2 files. Hope that will help you.

Corrupt file.xlsx
Good file.xlsx

Thank you.

@Bykiev
Copy link
Collaborator

Bykiev commented Apr 4, 2024

It seems to be smth wrong with shared formulas...
Can you please also provide your code to modificate the original file?

@JeanPhilippeLux
Copy link
Author

Hi, here the code. I clean up it because there is a connection to DB

string filename = "" //the filename goes here.

XSSFWorkbook newWorkbook = new();
XSSFSheet excelSheet = new();

initializeWorkbook(ref filename, ref newWorkbook, ref excelSheet);
int rowIndex = 1;

IRow row = excelSheet.CreateRow(rowIndex);

row.CreateCell(0).SetCellValue(12002219);
row.CreateCell(1).SetCellValue((double)2.2);

XSSFFormulaEvaluator.EvaluateAllFormulaCells(newWorkbook);

using FileStream fs = new(filename, FileMode.Create, FileAccess.Write);
newWorkbook.Write(fs);
fs.Close();

PrintMyExcelFile(filename);

//this code initialize the document
private void initializeWorkbook(ref string filename, ref XSSFWorkbook newWorkbook, ref XSSFSheet excelSheet)
{
newWorkbook = new();

 using (FileStream filestream = new(filename, FileMode.Open, FileAccess.Read))
 {
     newWorkbook = new XSSFWorkbook(filestream);
     filestream.Close();
 }

 int rowIndex = 0;

 excelSheet = (XSSFSheet)newWorkbook.GetSheet("A PRODUIRE");

 if (excelSheet != null)
 {
     while (excelSheet.GetRow(rowIndex) != null)
     {
         excelSheet.GetRow(rowIndex).GetCell(0)?.SetCellValue(0);
         excelSheet.GetRow(rowIndex).GetCell(1)?.SetCellValue(0);
         rowIndex++;
     }
 }
 else
 {
     excelSheet = (XSSFSheet)newWorkbook.CreateSheet("A PRODUIRE");
 }
 

 IRow row = excelSheet.CreateRow(0);

 row.CreateCell(0).SetCellValue("ItemId");
 row.CreateCell(1).SetCellValue("Qté à produire");
 row.CreateCell(2).SetCellValue(SelectedDate.Date);

}

//this code is for printing but crash at the line : Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
private void PrintMyExcelFile(string fileName)
{
Excel.Application excelApp = new();

 Excel.Workbook wb = excelApp.Workbooks.Open(fileName,
     Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
     Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
     Type.Missing, Type.Missing, Type.Missing, Type.Missing);

 Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
 for (int i = 1; i <= wb.Worksheets.Count; i++)
 {
     if (((Excel.Worksheet)wb.Worksheets[i]).Name == "MAIN")
     {
         ws = (Excel.Worksheet)wb.Worksheets[i];
         ws.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
         break;
     }
 }

 // Cleanup:
 GC.Collect();
 GC.WaitForPendingFinalizers();

 Marshal.FinalReleaseComObject(ws);

 wb.Close(false, Type.Missing, Type.Missing);
 Marshal.FinalReleaseComObject(wb);

 excelApp.Quit();
 Marshal.FinalReleaseComObject(excelApp);

}

Hope you will have the possibility to reproduce the error and fix it.

@Bykiev
Copy link
Collaborator

Bykiev commented Apr 4, 2024

The bug was already fixed in #1291

@Bykiev Bykiev closed this as completed Apr 4, 2024
@tonyqus tonyqus added this to the NPOI 2.7.1 milestone Apr 5, 2024
@tonyqus tonyqus added the formula label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants