Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate text in a spreadsheet cell using Apache POI?

How can I rotate the text within an HSSFCell class of Apache POI?

like image 310
Garudadwajan Avatar asked Jul 14 '09 12:07

Garudadwajan


2 Answers

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 myStyle = workbook.createCellStyle();
myStyle.setRotation((short)90);

HSSFCell c = row.createCell(columnNumber);
c.setCellStyle(myStyle);
like image 104
amischiefr Avatar answered Oct 17 '22 03:10

amischiefr


CellStyle cssVertical = wb.createCellStyle();
cssVertical.setFont(f);
cssVertical.setRotation((short)90);
like image 20
Ishan Liyanage Avatar answered Oct 17 '22 03:10

Ishan Liyanage