List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getPhysicalNumberOfRows
@Override public int getPhysicalNumberOfRows()
From source file:ddf.metrics.reporting.internal.rest.MetricsEndpointTest.java
License:Open Source License
@Test public void testGetMetricsDataAsXls() throws Exception { // Create RRD file that Metrics Endpoint will detect int dateOffset = 900; // 15 minutes in seconds createRrdFile(dateOffset);/*from w w w.j a v a 2 s .com*/ UriInfo uriInfo = createUriInfo(); // Get the metrics data from the endpoint MetricsEndpoint endpoint = getEndpoint(); endpoint.setMetricsDir(TEST_DIR); Response response = endpoint.getMetricsData("uptime", "xls", null, null, Integer.toString(dateOffset), "my label", "my title", uriInfo); cleanupRrd(); InputStream xls = (InputStream) response.getEntity(); assertThat(xls, not(nullValue())); HSSFWorkbook wb = new HSSFWorkbook(xls); assertThat(wb.getNumberOfSheets(), equalTo(1)); HSSFSheet sheet = wb.getSheet("Uptime"); assertThat(sheet, not(nullValue())); // Expect 7 rows: title + blank + column headers + 2 rows of samples + blank + // totalQueryCount assertThat(sheet.getPhysicalNumberOfRows(), equalTo(7)); // first row should have title in first cell HSSFRow row = sheet.getRow(0); assertThat(row, not(nullValue())); assertThat(row.getCell(0).getStringCellValue(), startsWith("Uptime for")); // third row should have column headers in first and second cells row = sheet.getRow(2); assertThat(row.getCell(0).getStringCellValue(), equalTo("Timestamp")); assertThat(row.getCell(1).getStringCellValue(), equalTo("Value")); // should have 2 rows of samples' data row = sheet.getRow(3); assertThat(row.getCell(0).getStringCellValue(), not(nullValue())); assertThat(row.getCell(1).getNumericCellValue(), not(nullValue())); row = sheet.getRow(4); assertThat(row.getCell(0).getStringCellValue(), not(nullValue())); assertThat(row.getCell(1).getNumericCellValue(), not(nullValue())); // last row should have totalQueryCount in first cell row = sheet.getRow(sheet.getLastRowNum()); assertThat(row.getCell(0).getStringCellValue(), startsWith("Total Count:")); assertThat(row.getCell(1).getNumericCellValue(), not(nullValue())); }
From source file:ddf.metrics.reporting.internal.rrd4j.RrdMetricsRetrieverTest.java
License:Open Source License
private void verifyWorksheet(HSSFSheet sheet, String metricName, int expectedNumberOfDataRows, boolean hasTotalCount) { // 3 = title + blank row + column headers int expectedTotalRows = 3 + expectedNumberOfDataRows; if (hasTotalCount) { expectedTotalRows += 2;/* w w w. ja va 2s .c o m*/ } assertThat(sheet.getPhysicalNumberOfRows(), equalTo(expectedTotalRows)); // first row should have title in first cell HSSFRow row = sheet.getRow(0); assertThat(row, not(nullValue())); assertThat(row.getCell(0).getStringCellValue(), startsWith(metricName + " for")); // third row should have column headers in first and second cells row = sheet.getRow(2); assertThat(row.getCell(0).getStringCellValue(), equalTo("Timestamp")); assertThat(row.getCell(1).getStringCellValue(), equalTo("Value")); // verify rows with the sample data, i.e., timestamps and values int endRow = 3 + expectedNumberOfDataRows; for (int i = 3; i < endRow; i++) { row = sheet.getRow(i); assertThat(row.getCell(0).getStringCellValue(), not(nullValue())); assertThat(row.getCell(1).getNumericCellValue(), not(nullValue())); } row = sheet.getRow(sheet.getLastRowNum()); if (hasTotalCount) { assertThat(row.getCell(0).getStringCellValue(), startsWith("Total Count:")); assertThat(row.getCell(1).getNumericCellValue(), not(nullValue())); } else { assertThat(row.getCell(0).getStringCellValue(), not(startsWith("Total Count:"))); } }
From source file:eionet.gdem.conversion.excel.writer.ExcelConversionHandler.java
License:Mozilla Public License
@Override public void addRow(String defStyle, String defType) { HSSFSheet sh = wb.getSheetAt(currentSheet); currentRow++;/*from w w w .j ava2s . c o m*/ sh.createRow(currentRow); currentRow = sh.getPhysicalNumberOfRows() - 1; currentCell = 0; if (rows == null) { rows = new ArrayList<RowColumnDefinition>(); } short idx = getStyleIdxByName(defStyle, ExcelStyleIF.STYLE_FAMILY_TABLE_CELL); RowColumnDefinition row = new RowColumnDefinition(defType, idx, defStyle); rows.add(row); }
From source file:file.open.util.parse.XlsParser.java
License:Open Source License
public void initParser(HSSFSheet sheet) { m_sheet = sheet; m_iNbRows = sheet.getPhysicalNumberOfRows(); }
From source file:gov.nih.nci.evs.browser.utils.ResolvedValueSetIteratorHolder.java
License:Open Source License
private void table(final HSSFSheet sheet) { if (sheet == null) { return;/*ww w . j a v a 2s . c om*/ } if (sheet.getDrawingPatriarch() != null) { final List<HSSFShape> shapes = sheet.getDrawingPatriarch().getChildren(); for (int i = 0; i < shapes.size(); ++i) { if (shapes.get(i) instanceof HSSFPicture) { try { // Gain access to private field anchor. final HSSFShape pic = shapes.get(i); final Field f = HSSFShape.class.getDeclaredField("anchor"); f.setAccessible(true); final HSSFClientAnchor anchor = (HSSFClientAnchor) f.get(pic); // Store picture cell row, column and picture data. if (!pix.containsKey(anchor.getRow1())) { pix.put(anchor.getRow1(), new HashMap<Short, List<HSSFPictureData>>()); } if (!pix.get(anchor.getRow1()).containsKey(anchor.getCol1())) { pix.get(anchor.getRow1()).put(anchor.getCol1(), new ArrayList<HSSFPictureData>()); } pix.get(anchor.getRow1()).get(anchor.getCol1()) .add(book.getAllPictures().get(((HSSFPicture) pic).getPictureIndex())); } catch (final Exception e) { throw new RuntimeException(e); } } } } out.append("<table cellspacing='0' style='border-spacing:0; border-collapse:collapse;'>\n"); for (rowIndex = 0; rowIndex < sheet.getPhysicalNumberOfRows(); ++rowIndex) { tr(sheet.getRow(rowIndex)); } out.append("</table>\n"); }
From source file:gov.nih.nci.evs.browser.utils.ResolvedValueSetIteratorHolder.java
License:Open Source License
private void table(final HSSFSheet sheet, int startIndex, int col, String code, boolean cdisc) { resolvedValueSetList = new ArrayList(); if (sheet == null) { return;/* ww w . j a v a 2 s .c om*/ } if (sheet.getDrawingPatriarch() != null) { final List<HSSFShape> shapes = sheet.getDrawingPatriarch().getChildren(); for (int i = 0; i < shapes.size(); ++i) { if (shapes.get(i) instanceof HSSFPicture) { try { // Gain access to private field anchor. final HSSFShape pic = shapes.get(i); final Field f = HSSFShape.class.getDeclaredField("anchor"); f.setAccessible(true); final HSSFClientAnchor anchor = (HSSFClientAnchor) f.get(pic); // Store picture cell row, column and picture data. if (!pix.containsKey(anchor.getRow1())) { pix.put(anchor.getRow1(), new HashMap<Short, List<HSSFPictureData>>()); } if (!pix.get(anchor.getRow1()).containsKey(anchor.getCol1())) { pix.get(anchor.getRow1()).put(anchor.getCol1(), new ArrayList<HSSFPictureData>()); } pix.get(anchor.getRow1()).get(anchor.getCol1()) .add(book.getAllPictures().get(((HSSFPicture) pic).getPictureIndex())); } catch (final Exception e) { throw new RuntimeException(e); } } } } out.append("<table id=\"" + "rvs_table" + "\" width=\"915\" class=\"mt\">\n"); tr(sheet.getRow(0)); StringBuffer buf = new StringBuffer(); tr(sheet.getRow(0), buf); String t = buf.toString(); resolvedValueSetList.add(t); int rows = sheet.getPhysicalNumberOfRows(); for (int i = startIndex; i <= rows; i++) { HSSFRow row = sheet.getRow(i); if (row != null) { if (col != -1) { HSSFCell cell = row.getCell(col); if (cell != null) { String value = null; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: value = cell.getCellFormula(); break; case HSSFCell.CELL_TYPE_NUMERIC: value = "" + cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; default: } if ((cdisc && i == startIndex) || (value != null && value.compareTo(code) == 0)) { tr(row); buf = new StringBuffer(); tr(row, buf); t = buf.toString(); resolvedValueSetList.add(t); } } } else { tr(row); buf = new StringBuffer(); tr(row, buf); t = buf.toString(); resolvedValueSetList.add(t); } } } out.append("</table>\n"); resolvedValueSetIterator = resolvedValueSetList.listIterator(); }
From source file:Importers.ExcelImporter.java
License:Apache License
@Override public DefaultMutableTreeNode readFile(File file) { System.out.println("==ExcelImporter=readFile: " + file.getAbsolutePath()); DefaultMutableTreeNode root = new DefaultMutableTreeNode("vulns"); try {/* w ww . jav a2 s.c om*/ POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file)); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row; HSSFCell cell; int rows; // No of rows rows = sheet.getPhysicalNumberOfRows(); int cols = 0; // No of columns int tmp = 0; // This trick ensures that we get the data properly even if it doesn't start from first few rows for (int i = 0; i < 10 || i < rows; i++) { row = sheet.getRow(i); if (row != null) { tmp = sheet.getRow(i).getPhysicalNumberOfCells(); if (tmp > cols) { cols = tmp; } } } for (int r = 1; r < rows; r++) { row = sheet.getRow(r); if (row != null) { // Create a new vuln Vulnerability vuln = new Vulnerability(); vuln.setTitle("NEW"); vuln.setIs_custom_risk(true); vuln.setRisk_category("None"); for (int c = 0; c < cols; c++) { cell = row.getCell(c); if (cell != null) { // Your code here String value = cell.getStringCellValue(); switch (c) { case 1:// title vuln.setTitle(value); break; case 2: // Risk CellStyle style = cell.getCellStyle(); short colorIdx = style.getFillForegroundColor(); HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette(); HSSFColor color = palette.getColor(colorIdx); String cc = color.getHexString(); System.out.println(cc); if (cc.equalsIgnoreCase("8080:8080:0")) { vuln.setRisk_category("Critical"); } else if (cc.equalsIgnoreCase("FFFF:0:0")) { vuln.setRisk_category("High"); } else if (cc.equalsIgnoreCase("FFFF:6666:0")) { vuln.setRisk_category("Medium"); } else if (cc.equalsIgnoreCase("F2F2:ECEC:0")) { vuln.setRisk_category("Low"); } else if (cc.equalsIgnoreCase("0:0:FFFF")) { vuln.setRisk_category("Info"); } break; case 3:// cvss string System.out.println(value); if (value.equalsIgnoreCase("No CVSS Vector")) { vuln.setIs_custom_risk(true); } else { vuln.setIs_custom_risk(false); vuln.setCvss_vector_string("CVSS2#" + value); } break; case 4://Description vuln.setDescription(value); break; case 5://Recommendation vuln.setRecommendation(value); break; case 6://Affected Hosts try { String[] lines = value.split("\n"); for (String line : lines) { String[] bits = line.split(" "); Host host = new Host(); host.setIp_address(bits[0]); String portprotocol = bits[2]; host.setPortnumber(portprotocol.split("/")[0]); host.setProtocol(portprotocol.split("/")[1]); vuln.addAffectedHost(host); } } catch (Exception ex) { ; } break; } } } System.out.println(vuln); root.add(new DefaultMutableTreeNode(vuln)); } } } catch (Exception ex) { ex.printStackTrace(); } return root; }
From source file:include.excel_import.XlsInfo.java
License:Open Source License
public int getRowCount(String sheetName) { if (rowCount.containsKey(sheetName)) { return ((Integer) rowCount.get(sheetName)).intValue(); }//from w w w. j a v a 2s. c o m HSSFSheet sheet = getSheetForSheetName(sheetName); int rowssize = sheet.getPhysicalNumberOfRows(); int size = 0; for (int i = 0; i < rowssize; i++) { HSSFRow row = sheet.getRow(i); if (row != null) size++; row = null; } Integer mysize = new Integer(size); rowCount.put(sheetName, mysize); sheet = null; mysize = null; //System.gc(); return size; }
From source file:it.cnr.ibimet.bikeclimate.backingbeans.FotovoltaicDataBean.java
public void postProcessXLS(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0); HSSFRow header = sheet.getRow(0);/*from w ww . j a v a 2 s .c om*/ HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.GREEN.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //Create header for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) { header.getCell(i).setCellStyle(cellStyle); header.getCell(i).setCellValue(columns.get(i).getHeader()); } //create data table for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) { header = sheet.getRow(i); for (int j = 0; j < header.getPhysicalNumberOfCells(); j++) { header.getCell(j).setCellValue(dati.get(i).get(columns.get(j).getProperty())); } } }
From source file:it.cnr.ibimet.bikeclimate.backingbeans.FotovoltaicDataBean.java
public void postProcessXLSStat(Object document) { HSSFWorkbook wb = (HSSFWorkbook) document; HSSFSheet sheet = wb.getSheetAt(0); HSSFRow header = sheet.getRow(0);//from ww w . jav a 2 s . co m HSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setFillForegroundColor(HSSFColor.GREEN.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //Create header for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) { header.getCell(i).setCellStyle(cellStyle); header.getCell(i).setCellValue(columnsStat.get(i).getHeader()); } //create data table for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) { header = sheet.getRow(i); for (int j = 0; j < header.getPhysicalNumberOfCells(); j++) { header.getCell(j).setCellValue(datiStat.get(i).get(columnsStat.get(j).getProperty())); } } }