Java用样式创建Excel

时间:2018-07-19 07:00:19

标签: java excel

加入样式和字体时遇到问题。最后,当我创建excel时,excel会成功,但是我的excel没有样式和字体,他什么也没有,只有data,我需要background-color:红色和行中== 0的纯白色

我的代码:

try {
    String filename = pathTempdownloadFile;
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet(eyelash);

    CellStyle backgroundStyle = workbook.createCellStyle();
    HSSFFont font = workbook.createFont();
    backgroundStyle.setFillBackgroundColor(IndexedColors.RED.getIndex());
    font.setColor(IndexedColors.WHITE.getIndex());

    HSSFRow rowhead = sheet.createRow((short) 0);
    rowhead.createCell(0).setCellValue("YEAR");
    rowhead.createCell(1).setCellValue("MONTH");
    rowhead.createCell(2).setCellValue("NAME)");
    rowhead.createCell(3).setCellValue("SURNAME");

    rowhead.setRowStyle(backgroundStyle);
    backgroundStyle.setFont(font);

    FileOutputStream fileOut = new FileOutputStream(filename);
    workbook.write(fileOut);
    fileOut.close();
    workbook.close();

} catch (Exception ex) {
    System.out.println(ex);
}

重复:我可以用数据创建excel,但是我的excel既没有样式也没有字体。

1 个答案:

答案 0 :(得分:2)

这应该有效:

optionalSync(sync) { self.tasksInQueue[userID] }
相关问题