0

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:

enter image description here

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:

enter image description here

the light gray color has gone after editting. How can I keep the color?

Angus B.
  • 23
  • 1
  • 8
  • "because the solution for this would be the same for both modules": I doubt that. I suspect it is a `NPOI` issue. It looks like `NPOI` does not know what tint values mean exactly and that they can be negative too. Gray can be made two ways. There is white theme color made darker using a negative tint value. And there is black theme color made lighter using a positive tint value. Seems all negative tint values are not more stored after rewritig using `NPOI`. So white is only white but no more darkter white. `Apache Poi` does not behave that way. – Axel Richter Nov 16 '21 at 18:10
  • @AxelRichter Thanks. I didn't actual check it if `Apache POI` has the same issue. So I shouldn't have mention about `Apache POI`. As for the solution, there is no solution as "`NPOI` does not know what tint values mean exactly", right? – Angus B. Nov 17 '21 at 09:44
  • I am not using `NPOI` so that was a suspicion only. What `NPOI` version are you using? Do use the latest on https://github.com/nissl-lab/npoi. You also could file that issue to https://github.com/nissl-lab/npoi/issues. – Axel Richter Nov 17 '21 at 10:01
  • @AxelRichter `NPOI 2.5.5`. I filed this issue on github. [github.com/nissl-lab/npoi/issues/695](https://github.com/nissl-lab/npoi/issues/695). Thank you. – Angus B. Nov 18 '21 at 02:10

0 Answers0