I code in C#. I use NPOI(version 2.5.5). But I link this OP to Apache POI as well because the solution for this would be the same for both modules.
I have this excel file whose extention is .xlsx
:
I editted the Excel sheet via NPOI.
code:
private void button_editByNpoi_Click(object sender, EventArgs e)
{
string filePath = destFileName;
IWorkbook workbook;
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
workbook = new XSSFWorkbook(fs);
}
/*
//1枚目のシートを取得
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);
}
}
As the result, I got this excel sheet:
the light gray color has gone after editting. How can I keep the color?