Page 1 of 1

Row and Cell storage in org.xlsx.sml.SheetData

PostPosted: Fri Feb 18, 2011 8:34 am
by fracai
While filling cells I realized that I was creating and adding a new cell and row for each entry.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        SheetData sheetData = sheet.getJaxbElement().getSheetData();

        Row row = Context.getsmlObjectFactory().createRow();
        Cell cell = Context.getsmlObjectFactory().createCell();

        cell.setV(value);

        cell.setR(colPos+rowPos); // "A1"
        row.setR(rowPos); // 1
        row.getC().add(cell);

        sheetData.getRow().add(row);
Parsed in 0.015 seconds, using GeSHi 1.0.8.4

Short of looping through the List returned by getRow() and checking the value of row.getR(), is there a better way to reuse Rows? Store my own HashMap? getRow().get(index), for example, isn't guaranteed to return the Row with R equal to index.

Or does this even matter? Having multiple Row elements with the same R property doesn't seem to cause problems, but it seems like reuse would be more efficient.