Changeset 7671


Ignore:
Timestamp:
Mar 21, 2019, 1:35:39 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2161: Import data from Excel files

Fixes a problem with some columns that are missing if the some rows have empty cells at the end of the line.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/excel/XlsxToCsvUtil.java

    r7664 r7671  
    362362        if (row == null || row.getPhysicalNumberOfCells() == 0) continue; // Empty row -- skip it
    363363        minCol = Math.min(minCol, row.getFirstCellNum());
    364         maxCol = Math.max(maxCol, row.getLastCellNum()); // Note! getLastCellNum() returns index of last cell+1 that contains data!
     364        int maxRowCol = row.getLastCellNum(); // Note! getLastCellNum() returns index of last cell+1 that contains data!
    365365       
    366366        // Sometimes there are a lot of empty or otherwise unused cells to the right on each row...
     
    369369        do
    370370        {
    371           maxCol--;
    372           if (maxCol < 0) break;
    373           Cell c = row.getCell(maxCol);
     371          maxRowCol--;
     372          if (maxRowCol < 0) break;
     373          Cell c = row.getCell(maxRowCol);
    374374          cellType = c == null ? CellType.BLANK : c.getCellType();
    375375          if (cellType == CellType.FORMULA && evaluateFormulas)
     
    380380
    381381        // Ok, found data on this row
    382         if (maxCol >= 0) lastRowWithData = rowNo;
     382        if (maxRowCol >= 0) lastRowWithData = rowNo;
     383        maxCol = Math.max(maxCol, maxRowCol);
    383384      }
    384385      this.lastRow = lastRowWithData;
     
    586587        }
    587588        out.append(rowSeparator);
    588       }     
    589      
     589      }
    590590      csvBytes = out.toString().getBytes(charset);
    591591    }
Note: See TracChangeset for help on using the changeset viewer.