Changeset 34072 in osm for applications
- Timestamp:
- 2018-02-19T23:17:09+01:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/opendata
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/opendata/includes/org/apache/poi/hssf/usermodel/HSSFRow.java
r28000 r34072 18 18 package org.apache.poi.hssf.usermodel; 19 19 20 import java.util.Iterator;21 import java.util.NoSuchElementException;22 23 20 import org.apache.poi.hssf.record.CellValueRecordInterface; 24 21 import org.apache.poi.hssf.record.RowRecord; 25 22 import org.apache.poi.ss.SpreadsheetVersion; 26 import org.apache.poi.ss.usermodel.Cell;27 23 import org.apache.poi.ss.usermodel.Row; 28 24 … … 102 98 * the maximum number of columns supported by the Excel binary format (.xls) 103 99 */ 100 @Override 104 101 public HSSFCell createCell(int column) 105 102 { … … 119 116 * the maximum number of columns supported by the Excel binary format (.xls) 120 117 */ 118 @Override 121 119 public HSSFCell createCell(int columnIndex, int type) 122 120 { … … 164 162 * @throws IndexOutOfBoundsException if the row number is not within the range 0-65535. 165 163 */ 164 @Override 166 165 public void setRowNum(int rowIndex) { 167 166 int maxrow = SpreadsheetVersion.EXCEL97.getLastRowIndex(); … … 180 179 * @return the row number (0 based) 181 180 */ 181 @Override 182 182 public int getRowNum() 183 183 { … … 190 190 * @return the HSSFSheet that owns this row 191 191 */ 192 @Override 192 193 public HSSFSheet getSheet() 193 194 { 194 195 return sheet; 195 196 } 196 197 197 198 198 /** … … 240 240 } 241 241 242 243 242 /** 244 243 * Get the hssfcell representing a given column (logical cell) … … 250 249 * @return HSSFCell representing that column or null if undefined. 251 250 */ 251 @Override 252 252 public HSSFCell getCell(int cellnum) { 253 253 return getCell(cellnum, book.getMissingCellPolicy()); … … 263 263 * @return representing that column or null if undefined + policy allows. 264 264 */ 265 @Override 265 266 public HSSFCell getCell(int cellnum, MissingCellPolicy policy) { 266 267 HSSFCell cell = retrieveCell(cellnum); … … 285 286 286 287 /** 288 * Gets the index of the last cell contained in this row <b>PLUS ONE</b>. The result also 289 * happens to be the 1-based column number of the last cell. This value can be used as a 290 * standard upper bound when iterating over cells: 291 * <pre> 292 * short minColIx = row.getFirstCellNum(); 293 * short maxColIx = row.getLastCellNum(); 294 * for(short colIx=minColIx; colIx<maxColIx; colIx++) { 295 * HSSFCell cell = row.getCell(colIx); 296 * if(cell == null) { 297 * continue; 298 * } 299 * //... do something with cell 300 * } 301 * </pre> 302 * 303 * @return short representing the last logical cell in the row <b>PLUS ONE</b>, or -1 if the 304 * row does not contain any cells. 305 */ 306 @Override 307 public short getLastCellNum() { 308 if (row.isEmpty()) { 309 return -1; 310 } 311 return (short) row.getLastCol(); 312 } 313 314 /** 287 315 * get the lowlevel RowRecord represented by this object - should only be called 288 316 * by other parts of the high level API … … 290 318 * @return RowRecord this row represents 291 319 */ 292 293 320 protected RowRecord getRowRecord() 294 321 { … … 296 323 } 297 324 298 /** 299 * @return cell iterator of the physically defined cells. 300 * Note that the 4th element might well not be cell 4, as the iterator 301 * will not return un-defined (null) cells. 302 * Call getCellNum() on the returned cells to know which cell they are. 303 * As this only ever works on physically defined cells, 304 * the {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy} has no effect. 305 */ 306 public Iterator<Cell> cellIterator() 307 { 308 return new CellIterator(); 309 } 310 /** 311 * Alias for {@link #cellIterator} to allow 312 * foreach loops 313 */ 314 public Iterator<Cell> iterator() { 315 return cellIterator(); 316 } 317 318 /** 319 * An iterator over the (physical) cells in the row. 320 */ 321 private class CellIterator implements Iterator<Cell> { 322 int thisId=-1; 323 int nextId=-1; 324 325 public CellIterator() 326 { 327 findNext(); 328 } 329 330 public boolean hasNext() { 331 return nextId<cells.length; 332 } 333 334 public Cell next() { 335 if (!hasNext()) 336 throw new NoSuchElementException("At last element"); 337 HSSFCell cell=cells[nextId]; 338 thisId=nextId; 339 findNext(); 340 return cell; 341 } 342 343 public void remove() { 344 if (thisId == -1) 345 throw new IllegalStateException("remove() called before next()"); 346 cells[thisId]=null; 347 } 348 349 private void findNext() 350 { 351 int i=nextId+1; 352 for(;i<cells.length;i++) 353 { 354 if(cells[i]!=null) break; 355 } 356 nextId=i; 357 } 358 359 } 360 361 325 @Override 362 326 public boolean equals(Object obj) 363 327 { -
applications/editors/josm/plugins/opendata/includes/org/apache/poi/ss/usermodel/Row.java
r28000 r34072 18 18 package org.apache.poi.ss.usermodel; 19 19 20 import java.util.Iterator;21 22 20 /** 23 21 * High level representation of a row of a spreadsheet. 24 22 */ 25 public interface Row extends Iterable<Cell>{23 public interface Row { 26 24 27 25 /** … … 75 73 */ 76 74 Cell getCell(int cellnum); 77 75 78 76 /** 79 77 * Returns the cell at the given (0 based) index, with the specified {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy} … … 88 86 89 87 /** 90 * @return Cell iterator of the physically defined cells. Note element 4 may 91 * actually be row cell depending on how many are defined! 88 * Gets the index of the last cell contained in this row <b>PLUS ONE</b>. The result also 89 * happens to be the 1-based column number of the last cell. This value can be used as a 90 * standard upper bound when iterating over cells: 91 * <pre> 92 * short minColIx = row.getFirstCellNum(); 93 * short maxColIx = row.getLastCellNum(); 94 * for(short colIx=minColIx; colIx<maxColIx; colIx++) { 95 * Cell cell = row.getCell(colIx); 96 * if(cell == null) { 97 * continue; 98 * } 99 * //... do something with cell 100 * } 101 * </pre> 102 * 103 * @return short representing the last logical cell in the row <b>PLUS ONE</b>, 104 * or -1 if the row does not contain any cells. 92 105 */ 93 Iterator<Cell> cellIterator();106 short getLastCellNum(); 94 107 95 108 /** -
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/tabular/XlsReader.java
r33518 r34072 58 58 if (row != null) { 59 59 List<String> result = new ArrayList<>(); 60 for (Cell cell : row) { 61 switch (cell.getCellType()) { 62 case Cell.CELL_TYPE_STRING: 63 result.add(cell.getRichStringCellValue().getString()); 64 break; 65 case Cell.CELL_TYPE_NUMERIC: 66 if (DateUtil.isCellDateFormatted(cell)) { 67 result.add(cell.getDateCellValue().toString()); 68 } else { 69 result.add(Double.toString(cell.getNumericCellValue())); 70 } 71 break; 72 case Cell.CELL_TYPE_BOOLEAN: 73 result.add(Boolean.toString(cell.getBooleanCellValue())); 74 break; 75 case Cell.CELL_TYPE_FORMULA: 76 result.add(cell.getCellFormula()); 77 break; 78 default: 79 result.add(""); 60 // Do not use iterator! It skips null values 61 for (int i = 0; i < row.getLastCellNum(); i++) { 62 Cell cell = row.getCell(i); 63 if (cell != null) { 64 switch (cell.getCellType()) { 65 case Cell.CELL_TYPE_STRING: 66 result.add(cell.getRichStringCellValue().getString()); 67 break; 68 case Cell.CELL_TYPE_NUMERIC: 69 if (DateUtil.isCellDateFormatted(cell)) { 70 result.add(cell.getDateCellValue().toString()); 71 } else { 72 result.add(Double.toString(cell.getNumericCellValue())); 73 } 74 break; 75 case Cell.CELL_TYPE_BOOLEAN: 76 result.add(Boolean.toString(cell.getBooleanCellValue())); 77 break; 78 case Cell.CELL_TYPE_FORMULA: 79 result.add(cell.getCellFormula()); 80 break; 81 default: 82 result.add(""); 83 } 84 } else { 85 result.add(""); 80 86 } 81 87 }
Note:
See TracChangeset
for help on using the changeset viewer.