[問題] NPOI的底色問題

看板C_Sharp (C#)作者 (克難)時間13年前 (2011/10/17 17:40), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
最近有用到NPOI來存取Excel 關於底色方面,不管我設定任何顏色,都是只顯示黑色 以下附上code: FileStream fs = new FileStream(fileName, FileMode.Open); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet st = (HSSFSheet)wb.GetSheetAt(0); HSSFCellStyle style = (HSSFCellStyle)wb.CreateCellStyle(); style.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.YELLOW.index; style.FillPattern = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND; Row headRow = sheet.GetRow(0); int cellCount = headRow.LastCellNum; for (int i = (st.FirstRowNum + 1); i <= st.LastRowNum; i++) { Row row = st.GetRow(i); for (int j = row.FirstCellNum; j < cellCount; j++) { if (long.TryParse(row.GetCell(j).ToString(), out number)) {//...} else { //我在這邊把Cell指定style設定的黃色,不過一律都變成黑色... HSSFCell cell = (HSSFCell)row.GetCell(j); cell.CellStyle = style; //... } //... } //... } 試了一個下午的NPOI,發現比interop.excel還要簡潔很多,唯獨這個顏色一直搞不定= = 請問我的程式哪裡出問題了嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.87.140.36

10/18 15:06, , 1F
自問自答:把FillBackgroundColor改成FillForegroundColor
10/18 15:06, 1F
文章代碼(AID): #1Ec_WFl3 (C_Sharp)
文章代碼(AID): #1Ec_WFl3 (C_Sharp)