繁体   English   中英

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

[英]Apache POI - Vertical Cell Alignment in HSSF Cell Format

有什么方法可以编写Apache POI中具有“垂直”文本方向的单元格吗? 我只能找到旋转整个文本的方法setRotation,而不是在应用“垂直”选项时Excel将其显示出来的方法。 看起来像这样:

本文

变成

t
h
i
s

t
e
x
t

根据HSSFCell.setRotation(short)

设置单元格中文本的旋转度

旋转-度(-90至90度之间,垂直为0xff)

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

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

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

Cell cell = row.createCell(0);
cell.setCellValue("this text");
cell.setCellStyle(styleVertical);
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在单元格中换行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM