I am trying to fill in a template xls with values, but even just opening with NPOI and saving as new file creates a corrupt xls.
There are a lot of things happening in the template, its locked, so I cannot alter anything to find the cause.
You can download the template here:
xls file
Heres the code I am using to open and save:
There are a lot of things happening in the template, its locked, so I cannot alter anything to find the cause.
You can download the template here:
xls file
Heres the code I am using to open and save:
private void btnNPOITest_Click(object sender, EventArgs e)
{
string templatePath = "C:\\Test\\MyTemplate.xls";
string outputPath = "C:\\Test\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
FileStream inFile = new FileStream(templatePath, FileMode.Open, FileAccess.Read);
NPOI.HSSF.UserModel.HSSFWorkbook workBook = new NPOI.HSSF.UserModel.HSSFWorkbook(inFile);
NPOI.SS.UserModel.ISheet sheet1 = workBook.GetSheet("Sheet1");
System.IO.File.Delete(outputPath);
FileStream outFile = new FileStream(outputPath, FileMode.Create);
workBook.Write(outFile);
outFile.Close();
MessageBox.Show("Done");
}