Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

New Post: NPOI Excel creating corrupt xls files

$
0
0
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:
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");
        }

Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>