带有JavaApachePOI的彩色头单元格
我想让我的标题行有不同的颜色。到目前为止,我只是对字体有不同的颜色,因为背景色并不像我所希望的那样工作。 我的输出文件应为xls格式带有JavaApachePOI的彩色头单元格,java,apache-poi,Java,Apache Poi,我想让我的标题行有不同的颜色。到目前为止,我只是对字体有不同的颜色,因为背景色并不像我所希望的那样工作。 我的输出文件应为xls格式 import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFWorkbook; ... String[] mylmcol = {"EmplNo", "LMSurname", "LMFirstname"};
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
...
String[] mylmcol = {"EmplNo", "LMSurname", "LMFirstname"};
String[] myusercol = {"UserID", "USRSurname", "USRFirstname"};
String[] rolecol = {"Group", "Role"};
String[] ackcol = {"ACKValue"};
XSSFWorkbook workbook_cbk_output = new XSSFWorkbook();
Sheet sheet_cbk_output = workbook_cbk_output.createSheet("UserList");
Font LMheaderFont = workbook_cbk_output.createFont();
LMheaderFont.setFontHeightInPoints((short) 12);
LMheaderFont.setColor(IndexedColors.SEA_GREEN.getIndex());
...
XSSFCellStyle headerCellStyleACK = workbook_cbk_output.createCellStyle();
headerCellStyleACK.setFont(ACKheaderFont);
//DOES NOT WORK:
headerCellStyleACK.setFillBackgroundColor(HSSFColor.AQUA.index);
headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Row headerRow_cbk = sheet_cbk_output.createRow(0);
for (int i = 0; i < mylmcol.length; i++) {
Cell cell = headerRow_cbk.createCell(i);
cell.setCellValue(mylmcol[i]);
cell.setCellStyle(headerCellStyleLM);
}
...
FileOutputStream OUTFILE = new FileOutputStream("Myoutput.xls");
workbook_cbk_output.write(OUTFILE);
OUTFILE.close();
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
导入org.apache.poi.xssf.usermodel.xssf工作簿;
...
字符串[]mylmcol={“empno”、“lmlasname”、“LMFirstname”};
字符串[]myusercol={“UserID”、“USRSurname”、“USRFirstname”};
字符串[]rolecol={“组”,“角色”};
字符串[]ackcol={“ACKValue”};
XSSFWorkbook工作簿_cbk_输出=新建XSSFWorkbook();
Sheet Sheet_cbk_output=工作簿_cbk_output.createSheet(“用户列表”);
Font-LMheaderFont=workbook\u cbk\u output.createFont();
LMheaderFont.setFontHeightInPoints((短)12);
setColor(IndexedColors.SEA_GREEN.getIndex());
...
XSSFCellStyle headerCellStyleACK=workbook_cbk_output.createCellStyle();
headerCellStyleACK.setFont(ACKheaderFont);
//不起作用:
headerCellStyleACK.setFillBackgroundColor(HSSFColor.AQUA.index);
headerCellStyle.setFillPattern(FillPatternType.SOLID\u前景);
Row headerRow\u cbk=sheet\u cbk\u output.createRow(0);
对于(int i=0;i
我尝试了命令
setFillBackgroundColor
,但这是igno。是否有其他用于背景着色的解决方案?如果使用XSSF工作表/CellStyle,则可以使用XSSFColor
而不是HSSFColor
。
对我来说,它与:
XSSFCellStyle headingStyle = workbook.createCellStyle();
headingStyle.setFillForegroundColor( new XSSFColor( new java.awt.Color( 207, 207, 207 ) ) );
headingStyle.setFillPattern( CellStyle.SOLID_FOREGROUND );
并将其应用于单元格/行:
Row rowHeadingStyle = styleSheet.createRow( 0 );
rowHeadingStyle.setRowStyle( headingStyle );
这是将背景色设置为所需的值 可能重复的