Hi,
Sorry, in my haste I described some of my wrapping code rather than POI code. Of course the saveAs(URI) does not exist, but I meant XSSFWorkbook.write. However, the problem still exists for me in that I get an IndexOutOfBoundsException when reading column width after the workbook is saved. I have isolated the problem in a simple unit test:
@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
    }

thanks,
Stuart

On 21/11/11 17:59, Stuart Owen wrote:
Hi,
I'm encountering a problem with a XSSFWorkbook after I save if using saveAs(URI). I am using the 3.8-beta4 version of apache poi. Before saving the workbook I can get the column width for a given column the contains a cell with some content, and this works fine. However after calling saveAs(URI), if I then read the same column width I receive an IndexOutOfBounds Exception, although the cell in that column appears
to still exist and successfully returns with its value.

java.lang.IndexOutOfBoundsException
at org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTWorksheetImpl.getColsArray(Unknown Source) at org.apache.poi.xssf.usermodel.helpers.ColumnHelper.getColumn1Based(ColumnHelper.java:103) at org.apache.poi.xssf.usermodel.helpers.ColumnHelper.getColumn(ColumnHelper.java:95) at org.apache.poi.xssf.usermodel.XSSFSheet.getColumnWidth(XSSFSheet.java:668)


thanks in advance,
Stuart.



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to