Auto size height for rows in Apache POI

user1007895 picture user1007895 · Oct 2, 2013 · Viewed 83.3k times · Source

I am inputting values into a spreadsheet using Apache POI. These values have newlines, and I was able to use this code successfully:

CellStyle style = cell.getCellStyle()
style.setWrapText(true)
cell.setCellStyle(style)

Unfortunately, while the text is wrapping correctly, the rows are not always growing in height enough to show the content. How do I ensure that my rows are always the correct height?

Answer

Franz Frühwirth picture Franz Frühwirth · Mar 18, 2015
currentRow.setHeight((short)-1)

Works for XSSFCell and Excel 2013