0

everyone, I created a method which generates an xlsx file and now I would like to auto-resize its columns. I tried this function:

//Auto Size columns
for (int i=0; i<columns.length; i++) sheet.autoSizeColumn(i);

The problem is that I get the error:

Failed resolution of: Ljava/awt/font/FontRenderContext;"

In this question I found out the exists a method which can I use, but I don't understand the mechanism. I know the exactly number of the character for each columns, but if I try to insert them manually as well nothing changes:

sheet.setColumnWidth(0, 8);

0: number of the column.
8: length of the word in the column

Babbara
  • 448
  • 1
  • 6
  • 21

1 Answers1

2

https://stackoverflow.com/a/59718764/8646362

Kindly check the link above. Column Width needs to be multiplied by 256. The width parameter is in units of 1/256th of a character width. Also it will throw an exception for java.lang.IllegalArgumentException - if width > 255*256 (the maximum column width in Excel is 255 characters)

KetkiK
  • 40
  • 5
  • Thanks for participating. Your answer was flagged for review as a 'late answer' because the question you have answered is (at this time) around 6 months old. It's a good idea to check the dates of the questions you're helping with to maximise the benfits your answers bring. – Software Engineer Mar 27 '20 at 14:20