https://bz.apache.org/bugzilla/show_bug.cgi?id=64165

            Bug ID: 64165
           Summary: Can't read in rows without 'r' attribute
           Product: POI
           Version: 4.1.x-dev
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

*I have a proposed fix for this (at least for XSSF). I'll attach a patch file
shortly, I just wanted to secure a Bugzilla number first. 

When creating a workbook from an existing file, I noticed that rows without an
'r' XML attribute (used for a row number in this case) are not indexed
correctly in the sheet object. See XSSFSheet.initRows() below. getRowNum()
returns -1 for all rows and all but the last row is lost. 

My version of Excel can handle these rows, it just reads them in consecutively.
When saving a workbook, it will add the 'r' attribute. I ran into this issue
when trying to read in a file that was exported from a JavaScript spreadsheet
tool. The authors of that tool claim their XML meets Microsoft's standards. 

Current code:
    private void initRows(CTWorksheet worksheetParam) {
        _rows.clear();
        tables = new TreeMap<>();
        sharedFormulas = new HashMap<>();
        arrayFormulas = new ArrayList<>();
        for (CTRow row : worksheetParam.getSheetData().getRowArray()) {
            XSSFRow r = new XSSFRow(row, this);
            // Performance optimization: explicit boxing is slightly faster 
            than auto-unboxing, though may use more memory
            //noinspection UnnecessaryBoxing
            final Integer rownumI = Integer.valueOf(r.getRowNum()); // 
            NOSONAR
            _rows.put(rownumI, r);
        }
    }

Proposed change: 
    private void initRows(CTWorksheet worksheetParam) {
        _rows.clear();
        tables = new TreeMap<>();
        sharedFormulas = new HashMap<>();
        arrayFormulas = new ArrayList<>();
        int rowIndex = 0;
        for (CTRow row : worksheetParam.getSheetData().getRowArray()) {
            XSSFRow r = new XSSFRow(row, this);
            if(r.getRowNum() == -1) {
                r.setRowNum(rowIndex);
                rowIndex++;
            }
            rowIndex = r.getRowNum();
            // Performance optimization: explicit boxing is slightly faster 
            than auto-unboxing, though may use more memory
            //noinspection UnnecessaryBoxing
            final Integer rownumI = Integer.valueOf(rowIndex); // NOSONAR
            _rows.put(rownumI, r);
        }
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to