Note that there are some explanatory texts on larger screens.

plurals
  1. POApache POI autoSizeColumn Resizes Incorrectly
    text
    copied!<p>I'm using Apache POI in java to create an excel file. I fill in the data then try to autosize each column, however the sizes are always wrong (and I <em>think</em> consistent). The first two rows are always(?) completely collapsed. When I autosize the columns in excel, it works perfectly.</p> <p>No blank cells are being written (I believe) and the resizing is the <strong>last</strong> thing I do.</p> <p><b>Here's the relevant code:</b> This is a boiled down version without error handling, etc.</p> <pre><code>public static synchronized String storeResults(ArrayList&lt;String&gt; resultList, String file) { if (resultList == null || resultList.size() == 0) { return file; } FileOutputStream stream = new FileOutputStream(file); //Create workbook and result sheet XSSFWorkbook book = new XSSFWorkbook(); Sheet results = book.createSheet("Results"); //Write results to workbook for (int x = 0; x &lt; resultList.size(); x++) { String[] items = resultList.get(x).split(PRIM_DELIM); Row row = results.createRow(x); for (int i = 0; i &lt; items.length; i++) { row.createCell(i).setCellValue(items[i]); } } //Auto size all the columns for (x = 0; x &lt; results.getRow(0).getPhysicalNumberOfCells(); x++) { results.autoSizeColumn(x); } //Write the book and close the stream book.write(stream); stream.flush(); stream.close(); return file; } </code></pre> <p>I know there are a few questions out there similar, but most of them are simply a case of sizing before filling in the data. And the few that aren't are more complicated/unanswered.</p> <p><strong>EDIT:</strong> I tried using a couple different fonts and it didn't work. Which isn't too surprising, as no matter what the font either all the columns should be completely collapsed or none should be.</p> <p>Also, because the font issue came up, I'm running the program on Windows 7.</p> <p><strong>SOLVED:</strong> It was a font issue. The only font that I found that worked was Serif.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload