You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2011/11/23 17:22:31 UTC

DO NOT REPLY [Bug 52233] New: IndexOutOfBoundsException when calling sheet.getColumnWidth after calling XSSFWorkbook.write

https://issues.apache.org/bugzilla/show_bug.cgi?id=52233

             Bug #: 52233
           Summary: IndexOutOfBoundsException when calling
                    sheet.getColumnWidth after calling XSSFWorkbook.write
           Product: POI
           Version: 3.8-dev
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: XSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: sowen@cs.manchester.ac.uk
    Classification: Unclassified


Whenever I write a XSSFWorkbook out using XSSFWorkbook.write, the book
afterwards is left in a state where calling getColumnWidth on one of its sheet
causes an IndexOutOfBoundsException. Below is a unit test that isolates the
problem (in this case it creates a new Workbook and constucts a sheet and
cells, but I also have the same problem when starting from an existing workbook
loaded through WorkbookFactory).

@Test
public void testColumnWidthPOI() throws Exception {
       XSSFWorkbook workbook = new XSSFWorkbook();
       XSSFSheet sheet = workbook.createSheet();
       XSSFRow row = sheet.createRow(0);
       XSSFCell cell = row.createCell(0);
       cell.setCellValue("hello world");
       assertEquals("hello
world",workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
       assertEquals(2048,workbook.getSheetAt(0).getColumnWidth(0)); //<-works

       //gets a UUID based temporary file
       File tmpDir = new File(System.getProperty("java.io.tmpdir"));
       String uuid = UUID.randomUUID().toString();
       File f = new File(tmpDir,uuid+".xlsx");

       BufferedOutputStream stream = new BufferedOutputStream(new
FileOutputStream(f));
       workbook.write(stream);
       stream.close();
       assertTrue(f.exists());

       assertEquals("hello
world",workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
       assertEquals(2048,workbook.getSheetAt(0).getColumnWidth(0)); //<- throws
IndexOutOfBoundsException
   }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 52233] IndexOutOfBoundsException when calling sheet.getColumnWidth after calling XSSFWorkbook.write

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52233

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Dominik Stadler <do...@gmx.at> ---
Fix differently now, it seems we need to set the colsArray to null in order to
produce valid XLSX-files, so we restore the colsArray after writing the
document out.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 52233] IndexOutOfBoundsException when calling sheet.getColumnWidth after calling XSSFWorkbook.write

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52233

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Dominik Stadler <do...@gmx.at> ---
I have now removed the setting of colsarray to null in XSSFSheet.write() to not
make the Workbook corrupt by writing it out. This fixes this bug, all existing
unit tests still run fine, not sure why the code was there initiallly, also the
SNV Log did not provide any useful information here.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 52233] IndexOutOfBoundsException when calling sheet.getColumnWidth after calling XSSFWorkbook.write

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52233

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #3 from Dominik Stadler <do...@gmx.at> ---
Reopening this bug as I need to revert the changes done for this Bug for now as
it breaks xlsx reading in Excel!

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 52233] IndexOutOfBoundsException when calling sheet.getColumnWidth after calling XSSFWorkbook.write

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52233

--- Comment #1 from Dominik Stadler <do...@gmx.at> ---
Analysis:
Class ColumnHelper has a member worksheet of type CTWorksheetImpl. If I look at
it before and after the call to write(), there is a line "  <main:cols/>"
missing after writing, so it seems writing is removing this line somehow.

When looking more closely the onSave() call in XSSFWorkbook.write() invokes
XSSFSheet.write(), which causes the removal via 

                worksheet.setColsArray(null);

I am not sure why the setColsArray() is done here and if not doing this would
have side-effects, but it would solve the problem here and probably some others
that are reported in some other Bugs when users try using a Workbook after
writing it out once.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org