List of usage examples for org.apache.poi.ss.usermodel Sheet getLastRowNum
int getLastRowNum();
From source file:org.ramadda.plugins.media.TabularOutputHandler.java
License:Open Source License
/** * _more_// w w w .j a v a 2 s. c om * * @param request _more_ * @param entry _more_ * @param suffix _more_ * @param inputStream _more_ * @param visitInfo _more_ * @param visitor _more_ * * @throws Exception _more_ */ private void visitXls(Request request, Entry entry, String suffix, InputStream inputStream, Visitor visitInfo, TabularVisitor visitor) throws Exception { // System.err.println("visitXls: making workbook"); Workbook wb = makeWorkbook(suffix, inputStream); // System.err.println("visitXls:" + visitInfo.getSkip() + " max rows:" + visitInfo.getMaxRows()+ " #sheets:" + wb.getNumberOfSheets()); int maxRows = visitInfo.getMaxRows(); for (int sheetIdx = 0; sheetIdx < wb.getNumberOfSheets(); sheetIdx++) { if (!visitInfo.okToShowSheet(sheetIdx)) { continue; } Sheet sheet = wb.getSheetAt(sheetIdx); // System.err.println("\tsheet:" + sheet.getSheetName() + " #rows:" + sheet.getLastRowNum()); List<List<Object>> rows = new ArrayList<List<Object>>(); int sheetSkip = visitInfo.getSkip(); for (int rowIdx = sheet.getFirstRowNum(); (rows.size() < maxRows) && (rowIdx <= sheet.getLastRowNum()); rowIdx++) { if (sheetSkip-- > 0) { continue; } Row row = sheet.getRow(rowIdx); if (row == null) { continue; } List<Object> cols = new ArrayList<Object>(); short firstCol = row.getFirstCellNum(); for (short col = firstCol; (col < MAX_COLS) && (col < row.getLastCellNum()); col++) { Cell cell = row.getCell(col); if (cell == null) { break; } Object value = null; int type = cell.getCellType(); if (type == cell.CELL_TYPE_NUMERIC) { value = new Double(cell.getNumericCellValue()); } else if (type == cell.CELL_TYPE_BOOLEAN) { value = new Boolean(cell.getBooleanCellValue()); } else if (type == cell.CELL_TYPE_ERROR) { value = "" + cell.getErrorCellValue(); } else if (type == cell.CELL_TYPE_BLANK) { value = ""; } else if (type == cell.CELL_TYPE_FORMULA) { value = cell.getCellFormula(); } else { value = cell.getStringCellValue(); } cols.add(value); } /** * ** TODO * org.ramadda.util.text.Row row = new Row(cols); * * if ( !visitInfo.rowOk(row)) { * if (rows.size() == 0) { * //todo: check for the header line * } else { * continue; * } * } */ rows.add(cols); } if (!visitor.visit(visitInfo, sheet.getSheetName(), rows)) { break; } } }
From source file:org.rdcit.tools.SpreadsheetReader.java
public int twoColumnsJunction(int sheetNum, int cellNum1, String cellValue1, int cellNum2, String cellValue2) { int rowNumber = 0; try {/*from w ww . ja v a 2s. c om*/ Sheet sheet = workbook.getSheetAt(sheetNum); int stop = sheet.getLastRowNum(); for (int i = 1; i <= stop; i++) { Row row = sheet.getRow(i); String sCellValue1 = getCellValueAsString(row.getCell(cellNum1)); String sCellValue2 = getCellValueAsString(row.getCell(cellNum2)); if ((sCellValue1.equals(cellValue1)) && (sCellValue2.equals(cellValue2))) { rowNumber = i; break; } } } catch (Exception ex) { } return rowNumber; }
From source file:org.rdcit.tools.SpreadsheetReader.java
public int getRowNum(int sheetNum, int cellNum, String cellValue) { int rowNumber = 0; try {/*from www. jav a 2 s .c om*/ Sheet sheet = workbook.getSheetAt(sheetNum); int stop = sheet.getLastRowNum(); for (int i = 1; i <= stop; i++) { Row row = sheet.getRow(i); if ((row.getCell(cellNum).getStringCellValue().equals(cellValue))) { rowNumber = i; break; } } } catch (Exception ex) { } return rowNumber; }
From source file:org.rdcit.tools.SpreadsheetWriter.java
public void appendNewRow(int sheetNum) { Sheet sheet = workbook.getSheetAt(sheetNum); sheet.createRow(sheet.getLastRowNum() + 1); }
From source file:org.rdcit.tools.SpreadsheetWriter.java
public void createNewRow(int sheetNum, int rowNum) { Sheet sheet = workbook.getSheetAt(sheetNum); if (rowNum <= sheet.getLastRowNum()) { sheet.shiftRows(rowNum, sheet.getLastRowNum(), 1); sheet.createRow(rowNum);/*from w w w . j av a2s .co m*/ } else { sheet.createRow(sheet.getLastRowNum() + 1); } }
From source file:org.rdcit.tools.SpreadsheetWriter.java
public int fingLastLabelOcc(int sheetNum, int labelCellNum, String label) { int rowNumber = 0; try {/*w ww . j ava2 s. c o m*/ Sheet sheet = workbook.getSheetAt(sheetNum); int stop = sheet.getLastRowNum(); for (int i = stop; i != 1; i--) { Row row = sheet.getRow(i); if ((row.getCell(labelCellNum).getStringCellValue().equals(label))) { rowNumber = i; break; } } } catch (Exception ex) { } return rowNumber; }
From source file:org.rdcit.tools.SpreadsheetWriter.java
public void appendNewCell(int sheetNum, int cellNum, String cellContent) { Sheet sheet = workbook.getSheetAt(sheetNum); Row row = sheet.getRow(sheet.getLastRowNum()); Cell cell = row.createCell(cellNum); cell.setCellValue(cellContent);/*from w w w. j a va2 s . com*/ }
From source file:org.rhq.helpers.perftest.support.reporting.ExcelExporter.java
License:Open Source License
/** * Append a row to the sheet//from w ww.j a va 2 s . c o m * @param sheet Sheet to append a new empty row to * @return the newly created row */ private Row appendRow(Sheet sheet) { int lastRow = sheet.getLastRowNum(); Row ret = sheet.createRow(lastRow + 1); return ret; }
From source file:org.rhq.helpers.perftest.test.ExcelExporterTest.java
License:Open Source License
/** * Test writing a workbook twice./*from w ww . ja v a2 s . c o m*/ * Should contain one Overview tab and one 'test' tab * with two times the same result * @throws Exception If anything goes wrong */ public void testRewriteSheets() throws Exception { /* * Run a dummy test. */ TestNG testNG = new TestNG(); testNG.setTestClasses(new Class[] { DummyTest.class }); TestListenerAdapter adapter = new TestListenerAdapter(); testNG.addListener(adapter); testNG.run(); // RHQ additional timing data Map<String, Long> timings = new HashMap<String, Long>(); timings.put("test", 123L); /* * Set up the reporter */ PerformanceReportExporter rep = new ExcelExporter(); rep.setBaseFile("test1"); rep.setRolling(PerformanceReporting.Rolling.NONE); /* * Write to .xls file twice */ rep.export(timings, adapter.getPassedTests().iterator().next()); rep.export(timings, adapter.getPassedTests().iterator().next()); /* * Now check the workbook written * But first delete an existing file */ File file = new File("test1.xls"); FileInputStream fis = new FileInputStream(file); Workbook wb = new HSSFWorkbook(fis); assert wb.getNumberOfSheets() == 2 : "Workbook does not have 2 sheets"; Sheet overview = wb.getSheetAt(0); assert overview.getSheetName().equals("Overview") : "Sheet 0 is not the Overview"; assert wb.getSheetAt(1).getSheetName().equals("DummyTest.one") : "Sheet 1 is not DummyTest.one"; // 0 based as opposed to xls where it rows are 1 based. assert overview.getLastRowNum() == 2 : "Last row of overview is not 4, but " + overview.getLastRowNum(); fis.close(); if (file.exists()) { assert file.delete(); } }
From source file:org.seasar.fisshplate.core.element.Root.java
License:Apache License
private void removeUnwantedRows(FPContext context) { ////w w w . j ava 2 s .c o m Sheet outSheet = context.getOutSheet(); int currentRowNum = context.getCurrentRowNum(); int lastRowNum = outSheet.getLastRowNum(); for (int i = currentRowNum; i <= lastRowNum; i++) { outSheet.removeRow(outSheet.getRow(i)); } }