如何使用 Apache POI 在电子表格单元格中旋转文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1125073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:54:06 来源:igfitidea点击:
How to rotate text in a spreadsheet cell using Apache POI?
提问by Garudadwajan
How can I rotate the text within an HSSFCell class of Apache POI?
如何在 Apache POI 的 HSSFCell 类中旋转文本?
回答by amischiefr
Use HSSFCellStyle, that class has a method called setRotation(short rotation) which will rotate the text. All you do is apply the cell style to a cell:
使用 HSSFCellStyle,该类有一个名为 setRotation(short rotation) 的方法,它将旋转文本。您所做的就是将单元格样式应用于单元格:
HSSFCellStyle myStyle = workbook.createCellStyle();
myStyle.setRotation((short)90);
HSSFCell c = row.createCell(columnNumber);
c.setCellStyle(myStyle);
回答by Ishan Liyanage
CellStyle cssVertical = wb.createCellStyle();
cssVertical.setFont(f);
cssVertical.setRotation((short)90);

