如何在Apache POI的HSSFCell类中旋转文本?
答案 0 :(得分:23)
使用HSSFCellStyle,该类有一个名为setRotation(短旋转)的方法,它将旋转文本。您所做的只是将单元格样式应用于单元格:
HSSFCellStyle myStyle = workbook.createCellStyle();
myStyle.setRotation((short)90);
HSSFCell c = row.createCell(columnNumber);
c.setCellStyle(myStyle);
答案 1 :(得分:0)
CellStyle cssVertical = wb.createCellStyle();
cssVertical.setFont(f);
cssVertical.setRotation((short)90);
答案 2 :(得分: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”属性。