我正在使用 Apache Poi 將數(shù)據(jù)寫入 Excel 表。我需要合并單元格并為合并的單元格設(shè)置背景。我有合并單元格的代碼,但我不知道如何為單元格設(shè)置背景或前景。// 此代碼是我用于合并單元格和設(shè)置單元格邊框的代碼CellRangeAddress cellRangeAddress = new CellRangeAddress(rowNum,rowNum,colNum,colNum);sheet.addMergedRegion(cellRangeAddress);RegionUtil.setBorderTop(CellStyle.BORDER_MEDIUM, mergedCell, sheet, workBook);RegionUtil.setBorderBottom(CellStyle.BORDER_MEDIUM, mergedCell,sheet, workBook);RegionUtil.setBorderLeft(CellStyle.BORDER_MEDIUM, mergedCell, sheet, workBook);RegionUtil.setBorderRight(CellStyle.BORDER_MEDIUM, mergedCell,sheet, workBook);我想要合并單元格的背景。請幫助我為合并的單元格設(shè)置背景或前景的代碼。
1 回答

紅顏莎娜
TA貢獻(xiàn)1842條經(jīng)驗 獲得超13個贊
嘗試以下步驟。如果您有任何問題,請告訴我。
從工作簿創(chuàng)建 CellStyle 對象,即 workbook.createCellStyle 設(shè)置 CellStyle 屬性,如 setAlignment、font、setFillForegroundColor、setFillPattern
然后將對象傳遞給 cell.setCellStyle
添加回答
舉報
0/150
提交
取消