I'm new to C# and Excel and I'm trying to copy data from one sheet (that is full of data) to a new one that is empty. I'm using NPOI and I've figured out a few things, but I have problems when adding the data.
The second sheet is empty, so all the cells are null (please correct me if I'm wrong). When I try to copy data from the first sheet to the second, nothing happens: the cells are not populated.
using (FileStream fs = new FileStream(@"C:\Users\MyDoc.xlsx", FileMode.Open, FileAccess.ReadWrite))
{
XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
//Load the sheets needed
var sheettoget = templateWorkbook.GetSheet("Sheet1");
var sheettoadd = templateWorkbook.GetSheet("Sheet2");
XSSFRow row = (XSSFRow)sheettoadd.CreateRow(0);
var cell = row.CreateCell(0);
var data = sheettoget.GetRow(0).GetCell(4).StringCellValue.ToString();
cell.SetCellValue(data); //the cell is not populated
}