1

我想使用 apache poi(vesrion 3.7)格式化生成的 excel 文件(使用动态报告生成)。我在格式化excel时基本上面临两个问题。

  1. 数字被视为文本,我在 excel 中收到警告消息(数字存储为文本)。
  2. 左缩进没有出现在 excel 中,尽管它出现在 PDF 和 HTML 中。

如何在 excel 报告中使用 apache poi 实现这两件事?

任何帮助将不胜感激。

提前致谢!

问候

希哈辛哈尔

4

1 回答 1

0

问题 1:数字存储为文本警告:

将单元格类型设置为数字:

Cell cell = sheet.getRow(0).createCell(2);      
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
cell.setCellValue(12345);

问题 2:单元格的左缩进

XSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_LEFT);
cell.setCellStyle(style);
于 2015-04-11T04:25:59.550 回答