【发布时间】:2014-07-02 08:43:07
【问题描述】:
我正在使用 apache POI 库从 java 代码创建一个 excel 报告。格式化excel单元格时遇到问题。请在下面找到一段代码。
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("coverageData");
int rownum = 0,cellnum=0;
Row row1 = sheet.createRow(rownum++);
Cell cell10 = row1.createCell(cellnum++);
cell10.setCellValue("cell data");
XSSFCellStyle row1style = (XSSFCellStyle)cell10.getCellStyle();
XSSFColor grayColor = new XSSFColor(Color.DARK_GRAY);
row1style.setFillBackgroundColor(grayColor);
cell10.setCellStyle(row1style);
try
{
//Write the workbook in file system
FileOutputStream out = new FileOutputStream(new File("P:\\automation\\Spreadsheet.xlsx"));
workbook.write(out);
out.close();
System.out.println("Spreadsheet.xlsx written successfully on disk.");
}
catch (Exception e)
{
e.printStackTrace();
}
这里的问题是我在最后一行代码中设置了 cell10 样式,但它在程序创建的 excel 表中没有受到影响。
提前致谢。
【问题讨论】:
标签: java excel apache-poi