I am facing a strange error while trying to save a workbook.
For work reasons, I have to open a template , compile some cell, and then save a copy with the added info.
I tried this code:
String patOfStartingFile =
String patOfResultingFile = @"somepath\newfile " + .id+ ".xlsm";
// Load the template into a NPOI workbook
XSSFWorkbook wb = new XSSFWorkbook(patOfResultingFile);
//calling writing methods to insert data into the workbook
//saving results into a new file.
FileStream xfile = new FileStream(patOfResultingFile, FileMode.Open, System.IO.FileAccess.Write);
The code works fine , but if I try to open the generated file with Excel(2013), it crashes.
I also tried to not set any cell ( only open, copy and save) and the problem occurs again.
Somehow Excel fails to open(it does not even show the empty workbook, crashes at the opening), and I really do not get why.
I tried also this method of saving the result:
using (FileStream file = new FileStream(patOfResultingFile, FileMode.Open, FileAccess.Read))
hssfwb = new XSSFWorkbook(file);
using (FileStream file = new FileStream(patOfResultingFile, FileMode.Open, FileAccess.Write))
And with this method Excel opens, and ask to recover the file content (failing) - which is even more odd.
I really do not have a clue, somebody knows something about it?