11

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.

Fitrah M
  • 983
  • 3
  • 17
  • 31

4 Answers4

15

I use

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

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

prule
  • 2,536
  • 31
  • 32
4

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

https://issues.apache.org/bugzilla/show_bug.cgi?id=52626

It's fixed on revision r1243240

Fitrah M
  • 983
  • 3
  • 17
  • 31
3

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)

Alfabravo
  • 7,493
  • 6
  • 46
  • 82
  • 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 08 '12 at 06:13
2

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.
Ali
  • 12,354
  • 9
  • 54
  • 83
  • using template seems to be nice. but what is `sheet.setDefaultRowHeight()` used for? Is it useless? – Fitrah M Feb 08 '12 at 06: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 08 '12 at 06:24