so I have the following code where I'm trying to modify the excel sheet. At 4th
row, I am adding additional cell with test
as a string but my file is not updating. I have read many articles on NPOI
library and found that few versions don't support writing the xlsx
file. But I guess I'm using 2.2.1
and it should do so. Please help me.
enter code here
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using Excel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
namespace PantheonProject
{
public class test
{
public static void testMethod()
{
XSSFWorkbook hssfwb;
using (FileStream file = new FileStream(@"/Users/harshloomba/Documents/workspace/PantheonProject/source.xlsx", FileMode.Open, FileAccess.Read))
{
hssfwb = new XSSFWorkbook(file);
file.Close();
}
ISheet sheet = hssfwb.GetSheetAt(0);
IRow row = sheet.GetRow(4);
//sheet.CreateRow(row.LastCellNum);
ICell cell = row.CreateCell(row.LastCellNum);
cell.SetCellValue("test");
for (int i = 0; i < row.LastCellNum; i++)
{
Console.WriteLine(row.GetCell(i));
}
using (FileStream file = new FileStream(@"/Users/harshloomba/Documents/workspace/PantheonProject/source.xlsx", FileMode.Open, FileAccess.Write))
{
hssfwb.Write(file);
file.Close();
}
}
}
}