Results 1 to 2 of 2
  1. #1
    bobv is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Default Problems with autoSizeColumn

    Hello,

    I am using POI 3.9 and am seeing strange results when trying to use the autoSizeColumn API. I am creating an SXSSFWorkbook, and after all rows have been created I run a loop to auto-size all columns:
    for (int i = 0; i < columns.size(); i++) {
    sh.autoSizeColumn(i);
    }
    There are still rows in memory when I run the loop, i.e. it hasn't all been flushed to disk.

    The auto-sizing worked fine in a test program where I had test data in all of the cells (all strings). However, now that "real" data is being used, what is happening is that only the columns with numeric data are visible (and auto-sized) after auto-sizing in the resulting spreadsheet. All other columns are hidden. I looked at the data inside the xlsx archive and I see this at the top of "sheet1.xml". The non-numeric cells are hidden with a width of 0. There is valid data in these columns.
    <cols>
    <col customWidth="1" hidden="1" width="0" max="2" min="1"/>
    <col customWidth="1" width="23.140625" max="3" min="3"/>
    <col customWidth="1" hidden="1" width="0" max="5" min="4"/>
    <col customWidth="1" width="11.5703125" max="6" min="6"/>
    <col customWidth="1" width="23.85546875" max="7" min="7"/>
    etc.

    If I do the auto-sizing manually in Excel on this file, it corrects the above problem. If I save it and open "sheet1.xml" I now see this:
    <cols>
    <col customWidth="1" bestFit="1" width="21.7109375" max="1" min="1"/>
    <col customWidth="1" bestFit="1" width="16.28515625" max="2" min="2"/>
    <col customWidth="1" bestFit="1" width="21.42578125" max="3" min="3"/>
    <col customWidth="1" bestFit="1" width="16.7109375" max="4" min="4"/>
    <col customWidth="1" bestFit="1" width="16.85546875" max="5" min="5"/>
    etc.

    Has anyone else seen a problem like this? I have tried things like:
    - making sure every cell has a value, even if it is an empty string
    - keeping the entire workbook in memory (not flushing)
    - setting all Cell types to CELL_TYPE_STRING

    But nothing seems to help.

    Thanks,
    Bob

  2. #2
    bobv is offline Member
    Join Date
    Oct 2013
    Posts
    2
    Rep Power
    0

    Default Re: Problems with autoSizeColumn

    One other thing I should mention: I am running this from within Tomcat and streaming the results to a browser, producing type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet". I think this has something to do with the problem. The below code mixes strings and numeric data, then auto-sizes. It works in a stand-alone program, but all string columns get hidden in the Tomcat/streamed results.

    Row row = null;
    Cell cell = null;
    for (int k = 0; k < 120; k++) {
    row = sh.createRow(k);
    for (int j = 0; j < columns.size(); j++) {
    cell = row.createCell(j);
    if (j % 2 == 0) {
    cell.setCellValue(String.valueOf(k * j));
    }
    else {
    cell.setCellValue("Hello there");
    }
    }
    }
    for (int i = 0; i < columns.size(); i++) {
    sh.autoSizeColumn(i);
    }

Similar Threads

  1. GUI problems on OSX
    By Melodia in forum New To Java
    Replies: 15
    Last Post: 09-12-2013, 07:33 PM
  2. InputStream/Jar Problems/File IO Problems
    By rdjava in forum Advanced Java
    Replies: 31
    Last Post: 01-17-2011, 11:12 AM
  3. RMI Problems
    By michaeln31 in forum New To Java
    Replies: 4
    Last Post: 10-23-2010, 12:52 PM
  4. problems with Jxl
    By Harpreet1111 in forum New To Java
    Replies: 1
    Last Post: 07-07-2010, 07:27 PM
  5. Problems in JSP : Need help
    By raj4u in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-07-2008, 10:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •