看板 C_Sharp 關於我們 聯絡資訊
最近有用到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
vulurn:自問自答:把FillBackgroundColor改成FillForegroundColor 10/18 15:06