I try to create new Excel file from a template Excel by copying, and edit the new Excel file by NPOI
. The template has cells whose background colors are light gray. But the background colors of the light gray dissapear on the new Excel. Only light gray background color dissapear but not other colors.
code:
private void button1_Click(object sender, EventArgs e)
{
File.Copy(
templateFilePath,
destFileName,
true);
string filePath = destFileName;
IWorkbook workbook;
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
workbook = new XSSFWorkbook(fs);
}
/*
ISheet sheet = workbook.GetSheetAt(0);
IRow row = sheet.GetRow(1);
ICell cell = row.GetCell(1);
cell.SetCellValue("a");
*/
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
workbook.Write(fs);
}
}
Template Excel:
The new Excel: