问题
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.
回答1:
I use
row.setHeightInPoints((2 * sheet.getDefaultRowHeightInPoints()));
to set it (for example) to 2 characters high.
回答2:
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)
回答3:
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
回答4:
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.
来源:https://stackoverflow.com/questions/9187048/how-to-set-excel-default-row-height-in-apache-poi