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))
{
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++)
{
}
using (FileStream file = new FileStream(@"D:\XYZ.xlsx", FileMode.Open, FileAccess.Write))
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();
}