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

Created Unassigned: XLSX file gets corrupted when write it using NPOI latest version [13546]

$
0
0
Hi Team,

I have downloaded NPOI 2.1.3 latest version from https://npoi.codeplex.com/releases.

When i am writing XLSX file using this dll then program successfully writes the rows (no error comes). but when i try to open the excel file then i get following error:

"Excel cannot open the file 'xyz.xlsx' because the file format or file extension
is not valid. Verify that the file has not been corrupted and the file extension matches the format of the fie."


I have wrote below code to wrote excel. Can you please help on this.

XSSFWorkbook xssfwb = new XSSFWorkbook();
IWorkbook iworkbook;


using (FileStream file = new FileStream(@"D:\XYZ.xlsx", FileMode.Open, FileAccess.Read))
{
hssfwb = new HSSFWorkbook(file);
iworkbook = hssfwb;
file.Close(); }

ISheet sheet1 = xssfwb.GetSheetAt(0);
for (int i = 1; i <= dt.Rows.Count; i++) //dt is a datatable which contain data to write into excel
{
IRow row = sheet1.CreateRow(i + 1);
for (int j = 0; j < 20; j++)
{
row.CreateCell(j).SetCellValue(x++); }
}

using (FileStream file = new FileStream(@"D:\XYZ.xlsx", FileMode.Open, FileAccess.Write))
{
hssfwb.Write(file);
file.Close();
}

Viewing all articles
Browse latest Browse all 1621

Trending Articles



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