Apache POI - HSSF 单元格格式的垂直单元格对齐

Apache POI - Vertical Cell Alignment in HSSF Cell Format

有什么方法可以用 Apache POI 中可用的 "Vertical" 文本方向编写单元格吗?我只能找到一种旋转整个文本的方法 setRotation,而不是在应用 "Vertical" 选项时将其显示为 Excel。视觉上看起来像:

本文

变成

t
h
i
s

t
e
x
t
CellStyle cs = wb.createCellStyle();//where 'wb' is the workbook
cs.setWrapText(true);
cell.setCellStyle(cs);//where 'cell' is the cell you wish to edit

之后,可以使用标准\n在单元格中换行

根据 HSSFCell.setRotation(short)

set the degree of rotation for the text in the cell

rotation - degrees (between -90 and 90 degrees, or 0xff for vertical)

因此,您首先需要创建一个(单个工作簿范围内的)单元格样式:

CellStyle styleVertical = wb.createCellStyle();
styleVertical.setRotation(0xff);

然后将其应用到您的单元格

Cell cell = row.createCell(0);
cell.setCellValue("this text");
cell.setCellStyle(styleVertical);