Cell vertical top alignment using poi

sahab singh picture sahab singh · Nov 3, 2011 · Viewed 44.2k times · Source

I am using POI api. Now my problem is that I am not able to align cell text vertically top.I am using getCellStyle().setAlignment(HSSFCellStyle.VERTICAL_TOP) to set alignment .

Yet when I open sheet it is not impacted.

Answer

Vlad picture Vlad · Jan 11, 2013

Had this problem as well, you will be supprised but to set vertical aligment to style in POI you should use setVerticalAlignment() function not setAlignment(). Example:

XSSFCellStyle styleSubHeader = (XSSFCellStyle) wb.createCellStyle();
styleSubHeader.setVerticalAlignment(CellStyle.VERTICAL_CENTER);