如何在 Apache POI 的 HSSFCell 类中旋转文本?
问问题
11483 次
3 回答
26
使用 HSSFCellStyle,该类有一个名为 setRotation(short rotation) 的方法,它将旋转文本。您所做的就是将单元格样式应用于单元格:
HSSFCellStyle myStyle = workbook.createCellStyle();
myStyle.setRotation((short)90);
HSSFCell c = row.createCell(columnNumber);
c.setCellStyle(myStyle);
于 2009-07-14T12:46:06.847 回答
1
CellStyle cssVertical = wb.createCellStyle();
cssVertical.setFont(f);
cssVertical.setRotation((short)90);
于 2016-08-12T09:18:36.473 回答
0
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
XSSFRow row = sheet.createRow(1);
XSSFCell cell = row.createCell(1);
XSSFCellStyle cs = workbook.createCellStyle();
cs.setRotation((short) 90); // set text rotation
cs.getStyleXf().setApplyAlignment(true); // <<< Important
cell.setCellValue("Vertical Text");
cell.setCellStyle(cs);
workbook.write(new FileOutputStream("out.xlsx"));
Apache POI 3.17,需要在 cellXfs 部分手动添加 alignment="true" 属性。
于 2020-09-15T07:56:22.773 回答