public int getRow() { Row row = cell.getRow(); return row.getRowNum(); } }
protected long readLongCell(Cell cell) { double d = cell.getNumericCellValue(); long l = (long) d; if (d - (double) l != 0.0) { throw new IllegalArgumentException("The keyCell (" + cell.getRow().getRowNum() + "," + cell.getColumnIndex() + ") with value (" + d + ") is expected to be a long."); } return l; }
protected double readDoubleParameter(Row row, String key) { Cell keyCell = row.getCell(0); if (!key.equals(keyCell.getStringCellValue())) { throw new IllegalArgumentException("The keyCell (" + keyCell.getRow().getRowNum() + "," + keyCell.getColumnIndex() + ") with value (" + keyCell.getStringCellValue() + ") is expected to have the key (" + key + ")"); } Cell valueCell = row.getCell(1); return valueCell.getNumericCellValue(); } }
protected String readStringParameter(Row row, String key) { Cell keyCell = row.getCell(0); if (!key.equals(keyCell.getStringCellValue())) { throw new IllegalArgumentException("The keyCell (" + keyCell.getRow().getRowNum() + "," + keyCell.getColumnIndex() + ") with value (" + keyCell.getStringCellValue() + ") is expected to have the key (" + key + ")"); } Cell valueCell = row.getCell(1); return valueCell.getStringCellValue(); }
protected void assertCellConstant(Cell cell, String constant) { if (!constant.equals(cell.getStringCellValue())) { throw new IllegalArgumentException("The cell (" + cell.getRow().getRowNum() + "," + cell.getColumnIndex() + ") with value (" + cell.getStringCellValue() + ") is expected to have the constant (" + constant + ")"); } }
final int rowNum = row.getRowNum(); final Integer rowNumI = Integer.valueOf(rowNum); // NOSONAR
private void readRegionList() throws IOException { Sheet sheet = readSheet(1, "Regions"); Row headerRow = sheet.getRow(0); assertCellConstant(headerRow.getCell(0), "Name"); assertCellConstant(headerRow.getCell(1), "Quantity maximum"); List<Region> regionList = new ArrayList<>(); regionMap = new LinkedHashMap<>(); long id = 0L; for (Row row : sheet) { if (row.getRowNum() < 1) { continue; } if (row.getCell(0) == null && row.getCell(1) == null) { continue; } Region region = new Region(); region.setId(id); id++; region.setName(readStringCell(row.getCell(0))); region.setQuantityMillisMaximum(parsePercentageMillis(readDoubleCell(row.getCell(1)))); regionList.add(region); regionMap.put(region.getName(), region); } solution.setRegionList(regionList); }
private void readSectorList() throws IOException { Sheet sheet = readSheet(2, "Sectors"); Row headerRow = sheet.getRow(0); assertCellConstant(headerRow.getCell(0), "Name"); assertCellConstant(headerRow.getCell(1), "Quantity maximum"); List<Sector> sectorList = new ArrayList<>(); sectorMap = new LinkedHashMap<>(); long id = 0L; for (Row row : sheet) { if (row.getRowNum() < 1) { continue; } if (row.getCell(0) == null && row.getCell(1) == null) { continue; } Sector sector = new Sector(); sector.setId(id); id++; sector.setName(readStringCell(row.getCell(0))); sector.setQuantityMillisMaximum(parsePercentageMillis(readDoubleCell(row.getCell(1)))); sectorList.add(sector); sectorMap.put(sector.getName(), sector); } solution.setSectorList(sectorList); }
if (row.getRowNum() < 2) { continue; throw new IllegalArgumentException("The row (" + row.getRowNum() + ") has " + row.getPhysicalNumberOfCells() + " cells, but is expected to have " + (ASSET_CLASS_PROPERTIES_COUNT + assetClassListSize) + " cells instead."); AssetClass assetClass = idToAssetClassMap.get(id); if (assetClass == null) { throw new IllegalStateException("The row (" + row.getRowNum() + ") has an assetClass id (" + id + ") that is not in the header."); Region region = regionMap.get(regionName); if (region == null) { throw new IllegalStateException("The row (" + row.getRowNum() + ") has a region (" + regionName + ") that is not in the regions sheet."); Sector sector = sectorMap.get(sectorName); if (sector == null) { throw new IllegalStateException("The row (" + row.getRowNum() + ") has a sector (" + sectorName + ") that is not in the sectors sheet.");
HSSFCell xcell = (HSSFCell) cell; if (xcell.isPartOfArrayFormulaGroup()) { String msg = "Row[rownum=" + row.getRowNum() + "] contains cell(s) included in a multi-cell array formula. You cannot change part of an array."; xcell.notifyArrayFormulaChanging(msg); Integer key = Integer.valueOf(row.getRowNum()); HSSFRow removedRow = _rows.remove(key); if (removedRow != row) {
_cellCache = new HashMap<>(_xs.getLastRowNum() * 3); for (final Row row : _xs) { final int rowNum = row.getRowNum(); for (final Cell cell : row) {
/** * Shift a formula using the supplied FormulaShifter * * @param row the row of the cell this formula belongs to. Used to get a reference to the parent workbook. * @param formula the formula to shift * @param formulaShifter the FormulaShifter object that operates on the parsed formula tokens * @return the shifted formula if the formula was changed, * <code>null</code> if the formula wasn't modified */ /*package*/ static String shiftFormula(Row row, String formula, FormulaShifter formulaShifter) { Sheet sheet = row.getSheet(); Workbook wb = sheet.getWorkbook(); int sheetIndex = wb.getSheetIndex(sheet); final int rowIndex = row.getRowNum(); XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb); try { Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex, rowIndex); String shiftedFmla = null; if (formulaShifter.adjustFormula(ptgs, sheetIndex)) { shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs); } return shiftedFmla; } catch (FormulaParseException fpe) { // Log, but don't change, rather than breaking logger.log(POILogger.WARN, "Error shifting formula on row ", row.getRowNum(), fpe); return formula; } }
if (region.isInRange(row.getRowNum(), column)) { if (!useMergedCells) {
@Override public void import(FileBean fileBean) { ByteArrayInputStream bis = new ByteArrayInputStream(filedBean.getFileData().getBytes()); Workbook workbook; try { if (fileBean.getFileData().getOriginalFilename().endsWith("xls")) { workbook = new HSSFWorkbook(bis); } else if (fileBean.getFileData().getOriginalFilename().endsWith("xlsx")) { workbook = new XSSFWorkbook(bis); } else { throw new IllegalArgumentException("Received file does not have a standard excel extension."); } for (Row row : sheet) { if (row.getRowNum() == 0) { Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); //go from cell to cell and do create sql based on the content } } } } catch (IOException e) { e.printStackTrace(); } }
File file = new File("D:/temp/test.xlsx"); FileInputStream fis = new FileInputStream(file); XSSFWorkbook wb = new XSSFWorkbook(fis); XSSFSheet sh = wb.getSheet("Hola"); System.out.println(sh.getLastRowNum()); System.out.println("Name: "+sh.getSheetName()); Row row = sh.getRow(1); System.out.println(row.getRowNum()); System.out.println("Val: "+sh.getRow(1).getCell(1).getStringCellValue());
private static int findRow(HSSFSheet sheet, String cellContent) { for (Row row : sheet) { for (Cell cell : row) { if (cell.getCellType() == Cell.CELL_TYPE_STRING) { if (cell.getRichStringCellValue().getString().trim().equals(cellContent)) { return row.getRowNum(); } } } } return 0; }
final int srcRowNum = srcRow.getRowNum(); final int destRowNum = getRowNum(); final int rowDifference = destRowNum - srcRowNum;
public void removeRowCells(Row row, int startCellNum, int endCellNum) { transformations.add( new RemoveTransformation( new Block(sheet, row.getRowNum(), startCellNum, row.getRowNum(), endCellNum)) ); ShiftTransformation shiftTransformation = new ShiftTransformation(new Block(sheet, row.getRowNum(), (int) (endCellNum + 1), row.getRowNum(), Integer.MAX_VALUE), 0, endCellNum - startCellNum + 1); transformations.add( shiftTransformation ); transformations.add( new RemoveTransformation( new Block(sheet, row.getRowNum(), (int) (row.getLastCellNum() - (endCellNum - startCellNum)), row.getRowNum(), row.getLastCellNum()))); formulaController.updateWorkbookFormulas( shiftTransformation ); TagBodyHelper.removeRowCells( sheet.getPoiSheet(), row, startCellNum, endCellNum ); }
private static void removeMergedRegions(Sheet sheet, Row row) { if (row != null && row.getFirstCellNum() >= 0 && row.getLastCellNum() >= 0) { int i = row.getRowNum(); for (int j = row.getFirstCellNum(), c = row.getLastCellNum(); j <= c; j++) { Util.removeMergedRegion(sheet, i, j); } } }