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: Select the cells that you wish to align. Right-click and then select "Format Cells" from the popup menu. When the Format Cells window appears, select the Alignment tab. Then select "Top" in the drop-down box called Vertical.
Use CellUtil. setAlignment(cell, HorizontalAlignment. CENTER); , the method setAlignment(Cell cell, Workbook workbook, short align) is deprecated now from 3.15-beta2.
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);
You can use this code :
style.setVerticalAlignment(VerticalAlignment.TOP);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With