Take the 2-minute tour ×

I'm using Apache POI 3.7 with Spring MVC 3.1.

How to set excel default row height in apache POI?

I've tried sheet.setDefaultRowHeight((short) 100) and sheet.setDefaultRowHeightInPoints(100)

but that doesn't work.

Any suggestion for this problem?

Thank you.

share|improve this question
add comment

4 Answers

I recall having this problem, I just ended up with 1 of 2 approaches:

  • setting with width and height on individual cells to get around this problem.
  • using an excel file as a template and writing to it.
share|improve this answer
using template seems to be nice. but what is sheet.setDefaultRowHeight() used for? Is it useless? –  Fitrah M Feb 8 '12 at 6:14
I honestly don't know. Back when i did this over a year ago, I just thought it was a bug or something. It's free... I'm just grateful for whatever works. The other advantage of using the template excel file is that you can style it to look pretty when it's output and that saves you a LOT of code. –  Ali Feb 8 '12 at 6:24
add comment

Create a style with the desired height and apply it to the cells you want to appear that way. Documentation can help you. For a moment thought there was a method to set height thru styles...

Documentation for the method you ask... "set the default row height for the sheet (if the rows do not define their own height) in twips (1/20 of a point)". Must be sure to cast the input to Short

setDefaultRowHeight( (Short) 100)

Also can set height for a row with row.setHeight(Short)

share|improve this answer
How to set row height from the style? There is no such style.setRowHeight() method. So, what is sheet.setDefaultRowHeight() used for? Is it useless? –  Fitrah M Feb 8 '12 at 6:13
add comment
up vote 1 down vote accepted

I've posted this issue on Apache POI's issue tracker and someone confirmed that it's a bug.


It's fixed on revision r1243240

share|improve this answer
add comment

I use

    row.setHeightInPoints((2 * sheet.getDefaultRowHeightInPoints()));

to set it (for example) to 2 characters high.

share|improve this answer
add comment

Your Answer


