List of usage examples for org.apache.poi.hssf.usermodel HSSFRow getSheet
@Override
public HSSFSheet getSheet()
From source file:com.elbeesee.poink.transreptor.HSSFRowToXML.java
License:Open Source License
public void onTransrept(INKFRequestContext aContext) throws Exception { IHSSFRowRepresentation aIHSSFRowRepresentation = (IHSSFRowRepresentation) aContext .sourcePrimary(IHSSFRowRepresentation.class); HSSFRow vRow = aIHSSFRowRepresentation.getRowReadOnly(); String vSheetName = vRow.getSheet().getSheetName(); StringBuilder vRowXML = new StringBuilder(); vRowXML.append("<row rowIndex=\""); vRowXML.append(vRow.getRowNum());// w w w . j a v a 2 s.c o m vRowXML.append("\" sheetIndex=\""); vRowXML.append(vRow.getSheet().getWorkbook().getSheetIndex(vSheetName)); vRowXML.append("\">"); // do the cells int i = 0; for (Iterator<Cell> vCellIterator = vRow.cellIterator(); vCellIterator.hasNext();) { HSSFCell vHSSFCell = (HSSFCell) vCellIterator.next(); IHSSFCellRepresentation vHSSFCellRepresentation = new HSSFCellImplementation(vHSSFCell); String vCellXML = aContext.transrept(vHSSFCellRepresentation, String.class); vRowXML.append(vCellXML); i = i + 1; } // vRowXML.append("</row>"); INKFResponse vResponse = aContext.createResponseFrom(vRowXML.toString()); vResponse.setExpiry(INKFResponse.EXPIRY_DEPENDENT); }
From source file:com.report.excel.ExcelToHtmlConverter.java
License:Apache License
/** * @return maximum 1-base index of column that were rendered, zero if none *//*ww w.ja v a 2s .c o m*/ protected int processRow(CellRangeAddress[][] mergedRanges, HSSFRow row, Element tableRowElement) { final HSSFSheet sheet = row.getSheet(); final short maxColIx = row.getLastCellNum(); if (maxColIx <= 0) return 0; final List<Element> emptyCells = new ArrayList<Element>(maxColIx); if (isOutputRowNumbers()) { Element tableRowNumberCellElement = htmlDocumentFacade.createTableHeaderCell(); //processRowNumber( row, tableRowNumberCellElement ); emptyCells.add(tableRowNumberCellElement); } int maxRenderedColumn = 0; for (int colIx = 0; colIx < maxColIx; colIx++) { if (!isOutputHiddenColumns() && sheet.isColumnHidden(colIx)) continue; CellRangeAddress range = ExcelToHtmlUtils.getMergedRange(mergedRanges, row.getRowNum(), colIx); if (range != null && (range.getFirstColumn() != colIx || range.getFirstRow() != row.getRowNum())) continue; HSSFCell cell = row.getCell(colIx); int divWidthPx = 0; if (isUseDivsToSpan()) { divWidthPx = getColumnWidth(sheet, colIx); boolean hasBreaks = false; for (int nextColumnIndex = colIx + 1; nextColumnIndex < maxColIx; nextColumnIndex++) { if (!isOutputHiddenColumns() && sheet.isColumnHidden(nextColumnIndex)) continue; if (row.getCell(nextColumnIndex) != null && !isTextEmpty(row.getCell(nextColumnIndex))) { hasBreaks = true; break; } divWidthPx += getColumnWidth(sheet, nextColumnIndex); } if (!hasBreaks) divWidthPx = Integer.MAX_VALUE; } Element tableCellElement = htmlDocumentFacade.createTableCell(); if (range != null) { if (range.getFirstColumn() != range.getLastColumn()) tableCellElement.setAttribute("colspan", String.valueOf(range.getLastColumn() - range.getFirstColumn() + 1)); if (range.getFirstRow() != range.getLastRow()) tableCellElement.setAttribute("rowspan", String.valueOf(range.getLastRow() - range.getFirstRow() + 1)); } boolean emptyCell; if (cell != null) { emptyCell = processCell(cell, tableCellElement, getColumnWidth(sheet, colIx), divWidthPx, row.getHeight() / 20f); } else { emptyCell = true; } if (emptyCell) { emptyCells.add(tableCellElement); } else { for (Element emptyCellElement : emptyCells) { tableRowElement.appendChild(emptyCellElement); } emptyCells.clear(); tableRowElement.appendChild(tableCellElement); maxRenderedColumn = colIx; } } return maxRenderedColumn + 1; }
From source file:com.wangzhu.poi.ExcelToHtmlConverter.java
License:Apache License
/** * @return maximum 1-base index of column that were rendered, zero if none *//*from w w w . j av a2s . c om*/ protected int processRow(CellRangeAddress[][] mergedRanges, HSSFRow row, Element tableRowElement) { final HSSFSheet sheet = row.getSheet(); final short maxColIx = row.getLastCellNum(); if (maxColIx <= 0) { return 0; } final List emptyCells = new ArrayList(maxColIx); if (this.isOutputRowNumbers()) { Element tableRowNumberCellElement = this.htmlDocumentFacade.createTableHeaderCell(); this.processRowNumber(row, tableRowNumberCellElement); emptyCells.add(tableRowNumberCellElement); } int maxRenderedColumn = 0; for (int colIx = 0; colIx < maxColIx; colIx++) { if (!this.isOutputHiddenColumns() && sheet.isColumnHidden(colIx)) { continue; } CellRangeAddress range = AbstractExcelUtils.getMergedRange(mergedRanges, row.getRowNum(), colIx); if ((range != null) && ((range.getFirstColumn() != colIx) || (range.getFirstRow() != row.getRowNum()))) { continue; } HSSFCell cell = row.getCell(colIx); int divWidthPx = 0; if (this.isUseDivsToSpan()) { divWidthPx = AbstractExcelConverter.getColumnWidth(sheet, colIx); boolean hasBreaks = false; for (int nextColumnIndex = colIx + 1; nextColumnIndex < maxColIx; nextColumnIndex++) { if (!this.isOutputHiddenColumns() && sheet.isColumnHidden(nextColumnIndex)) { continue; } if ((row.getCell(nextColumnIndex) != null) && !this.isTextEmpty(row.getCell(nextColumnIndex))) { hasBreaks = true; break; } divWidthPx += AbstractExcelConverter.getColumnWidth(sheet, nextColumnIndex); } if (!hasBreaks) { divWidthPx = Integer.MAX_VALUE; } } Element tableCellElement = this.htmlDocumentFacade.createTableCell(); if (range != null) { if (range.getFirstColumn() != range.getLastColumn()) { tableCellElement.setAttribute("colspan", String.valueOf((range.getLastColumn() - range.getFirstColumn()) + 1)); } if (range.getFirstRow() != range.getLastRow()) { tableCellElement.setAttribute("rowspan", String.valueOf((range.getLastRow() - range.getFirstRow()) + 1)); } } boolean emptyCell; if (cell != null) { emptyCell = this.processCell(cell, tableCellElement, AbstractExcelConverter.getColumnWidth(sheet, colIx), divWidthPx, row.getHeight() / 20f); } else { emptyCell = true; } if (emptyCell) { emptyCells.add(tableCellElement); } else { for (Iterator iterator = emptyCells.iterator(); iterator.hasNext();) { Element emptyCellElement = (Element) iterator.next(); tableRowElement.appendChild(emptyCellElement); } emptyCells.clear(); tableRowElement.appendChild(tableCellElement); maxRenderedColumn = colIx; } } return maxRenderedColumn + 1; }
From source file:gov.nih.nci.evs.browser.utils.ResolvedValueSetIteratorHolder.java
License:Open Source License
/** * (Each Excel sheet row becomes an HTML table row) Generates an HTML table * row which has the same height as the Excel row. * * @param row/*from ww w . jav a 2s . c o m*/ * The Excel row. */ private void tr(final HSSFRow row) { if (row == null) { return; } out.append("<tr "); // Find merged cells in current row. for (int i = 0; i < row.getSheet().getNumMergedRegions(); ++i) { final CellRangeAddress merge = row.getSheet().getMergedRegion(i); if (merge == null) return; if (rowIndex >= merge.getFirstRow() && rowIndex <= merge.getLastRow()) { mergeStart = merge.getFirstColumn(); mergeEnd = merge.getLastColumn(); break; } } out.append("style='"); if (row.getHeight() != -1) { out.append("height: ").append(Math.round(row.getHeight() / 20.0 * 1.33333)).append("px; "); } out.append("'>\n"); for (colIndex = 0; colIndex < row.getLastCellNum(); ++colIndex) { td(row.getCell(colIndex)); } out.append("</tr>\n"); }
From source file:gov.nih.nci.evs.browser.utils.ResolvedValueSetIteratorHolder.java
License:Open Source License
private void tr(final HSSFRow row, StringBuffer buf) { if (row == null) { return;/*ww w . jav a 2 s . c om*/ } buf.append("<tr "); // Find merged cells in current row. for (int i = 0; i < row.getSheet().getNumMergedRegions(); ++i) { final CellRangeAddress merge = row.getSheet().getMergedRegion(i); if (merge == null) return; if (rowIndex >= merge.getFirstRow() && rowIndex <= merge.getLastRow()) { mergeStart = merge.getFirstColumn(); mergeEnd = merge.getLastColumn(); break; } } buf.append("style='"); if (row.getHeight() != -1) { buf.append("height: ").append(Math.round(row.getHeight() / 20.0 * 1.33333)).append("px; "); } buf.append("'>"); for (colIndex = 0; colIndex < row.getLastCellNum(); ++colIndex) { td(row.getCell(colIndex)); td(row.getCell(colIndex), buf); } buf.append("</tr>"); }
From source file:gov.nih.nci.evs.browser.utils.ResolvedValueSetIteratorHolder.java
License:Open Source License
private void getRowData(Vector v, final HSSFRow row) { if (row == null) { return;//from w w w .j av a 2s .c o m } for (int i = 0; i < row.getSheet().getNumMergedRegions(); ++i) { final CellRangeAddress merge = row.getSheet().getMergedRegion(i); if (merge == null) return; if (rowIndex >= merge.getFirstRow() && rowIndex <= merge.getLastRow()) { mergeStart = merge.getFirstColumn(); mergeEnd = merge.getLastColumn(); break; } } StringBuffer buf = new StringBuffer(); for (colIndex = 0; colIndex < row.getLastCellNum(); ++colIndex) { if (colIndex > 0) { buf.append("|"); } String val = getCellData(row.getCell(colIndex)); if (val != null) { buf.append(val); } } v.add(buf.toString()); }
From source file:org.testeditor.core.importer.ExcelFileImporter.java
License:Open Source License
/** * Iterates through the cells in a row an creates a {@link TestDataRow} * Object./* ww w .j ava 2 s . c o m*/ * * @param row * row in excel sheet * @return TestDataRow */ @SuppressWarnings("rawtypes") private TestDataRow getTestDataRow(HSSFRow row) { int id = 0; Iterator cells = row.cellIterator(); TestDataRow testDataRow = new TestDataRow(); while (cells.hasNext()) { HSSFCell cell = (HSSFCell) cells.next(); for (int i = id; i < cell.getColumnIndex(); i++) { testDataRow.add(""); } id = cell.getColumnIndex() + 1; if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) { getTestDataNumericCell(testDataRow, cell); } else if (HSSFCell.CELL_TYPE_STRING == cell.getCellType()) { testDataRow.add(cell.getStringCellValue()); } else if (HSSFCell.CELL_TYPE_BOOLEAN == cell.getCellType()) { testDataRow.add(String.valueOf(cell.getBooleanCellValue())); } else if (HSSFCell.CELL_TYPE_FORMULA == cell.getCellType()) { HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(row.getSheet().getWorkbook()); CellValue cv = fe.evaluate(cell); testDataRow.add(cv.formatAsString()); } else if (HSSFCell.CELL_TYPE_BLANK == cell.getCellType()) { testDataRow.add(""); } else { if (LOGGER.isInfoEnabled()) { LOGGER.info("getTestData :: Unknown cell type"); } } } return testDataRow; }
From source file:phoenixplcscadahelper.AnaEkran.java
private void digitalOutput(HSSFRow row) { String tagName = row.getCell(1).toString(); String tagComment = row.getCell(2).toString(); String tagIO = row.getCell(3).toString(); digitalTagCount++;/* ww w. j a v a 2s . c o m*/ if (digitalTagCount == 1) { String header = "(* ### # # # ##### # # *)\n" + "(* # # # # ### # *)\n" + "(* # # # # # # # # # *)\n" + "(* # # # # # # # # # *)\n" + "(* # # # # # # # ####### # *)\n" + "(* ### # ## # # # # ##### *)\n\n\n\n"; girislerTextArea.append(header); cikislarTextArea.append(header); } plcGlobalTextArea.append(tagIO + "\tBOOL\tVAR_GLOBAL\t" + row.getCell(1).toString() + "\t\t\t0\t0\t0\t0\t0\t0\t\t0\t0\t\t\t\t\t0\t\n"); if (tagName.equals("YEDEK")) { } else { digitalTagCount++; plcGlobalTextArea.append(tagName + "W\tWORD\tVAR_GLOBAL\t" + tec(tagComment) + "\t\t\t0\t0\t1\t0\t0\t0\t\t0\t0\t\t\t\t\t0\t\n"); digitalTagCount++; plcGlobalTextArea.append(tagName + "\tBOOL\tVAR_GLOBAL\t" + tec(tagComment) + "\t\t\t0\t0\t0\t0\t0\t0\t\t0\t0\t\t\t\t\t0\t\n"); //modbus plc ksm initMbCikislarTextArea.append("if MODDATA[" + modbusOutNr + "] <> MODDATA2[" + modbusOutNr + "] then " + tagName + "W := MODDATA[" + modbusOutNr + "]; else MODDATA[" + modbusOutNr + "] := " + tagName + "W; end_if;\n"); } plcGlobalLabel.setText("Dijital Global Deikenler " + digitalTagCount + " Adet"); //CIKISLAR stl dosyas ierii if (tagName.equals("YEDEK")) { } else { int alrType = 0; String onFb = "false"; String offFb = "false"; int onFbRowNr = findRow(row.getSheet(), tagName + "_ON_FB"); if (onFbRowNr > 0) { onFb = row.getSheet().getRow(onFbRowNr).getCell(3).toString(); } int offFbRowNr = findRow(row.getSheet(), tagName + "_OFF_FB"); if (offFbRowNr > 0) { offFb = row.getSheet().getRow(offFbRowNr).getCell(3).toString(); } alrType = ((onFb.equals("false")) ? 0 : 1) + ((offFb.equals("false")) ? 0 : 2); // kn fb alarm var if (alrType > 0) { visuAlTextArea.append(tagName + "W.2\t" + tagName + " - " + tagComment); //esa alarm tag HSSFRow trow = esaWb.getSheet("Tags").createRow(esaRowNr); trow.createCell(0).setCellValue(""); trow.createCell(1).setCellValue(tagName); trow.createCell(2).setCellValue("Internal"); trow.createCell(3).setCellValue(""); trow.createCell(4).setCellValue(""); trow.createCell(5).setCellValue(""); trow.createCell(6).setCellValue(""); trow.createCell(7).setCellValue(""); trow.createCell(8).setCellValue("Boolean"); trow.createCell(9).setCellValue(""); trow.createCell(10).setCellValue(tagComment + " alarm var"); trow.createCell(11).setCellValue(0); trow.createCell(12).setCellValue(""); esaRowNr++; //esa AlarmScript ierii esaAlarmScriptTextArea.append("'" + tagName + "\na = ESAHMI.ESATAG.GetCurrentValue(\"" + tagName + "W\") And 4\nf = ESAHMI.ESATAG.WriteValue(\"" + tagName + "\" , a)\n"); //esa alarm xls HSSFRow arow = esaAWb.getSheet("Alarms").createRow(esaARowNr); arow.createCell(0).setCellValue(""); arow.createCell(1).setCellValue(tagName); arow.createCell(2).setCellValue("Bit"); arow.createCell(3).setCellValue(tagName); arow.createCell(4).setCellValue("AlarmPriority Error"); arow.createCell(5).setCellValue(tagComment + " alarm"); arow.createCell(6).setCellValue(1); esaARowNr++; } cikislarTextArea.append("(* " + tagIO + " - " + tagName + " - " + tagComment + " *)\n"); cikislarTextArea.append( "DIGOUT_FB_1(LOG_INP := " + tagName + ",OUT_WORD := " + tagName + "W,ALR_TYP := " + alrType + ",ALR_TIME := 5,FBON := " + onFb + ",FBOFF := " + offFb + ",AL_RST := ALRST);\n"); cikislarTextArea.append(tagName + "W := DIGOUT_FB_1.OUT_WORD;\n"); cikislarTextArea.append(tagIO + " := DIGOUT_FB_1.FIZ_OUT;\n\n\n"); } //Visu OPC tag listesi if (tagName.equals("YEDEK")) { } else { visuOpcTextArea.append("\t\t<OPCItem>\t<ItemID AccessPath=\"\" VTType=\"0\" Variable=\"" + tagName + "W\" EnableWrite=\"1\" EnableRead=\"1\" SyncDataStartup=\"0\" SyncWrite=\"1\" ReRead=\"0\">" + opcName + "." + tagName + "W</ItemID>\t</OPCItem>\t\t" + "\n"); //Visu Var deikenleri visuVarTextArea.append( "\t\t<Variable(Tag)> <Name Type=\"4\" AreaType=\"1\" Address=\"0\" Bit=\"0\" Description=\"" + tagIO + " - " + tagComment + "\" Shared=\"0\" Retentive=\"0\" InitQuality=\"192\">" + tagName + "W</Name>\t<EnableTrace DurationDays=\"730\">0</EnableTrace>\t" + "<EnableOPCServer>0</EnableOPCServer>\t<EnableNetworkClient EnableTCPIPServer=\"1\">0</EnableNetworkClient>\t" + "<EnableMapRealTimeToDB>0</EnableMapRealTimeToDB>\t" + "</Variable(Tag)>\t\t" + "\n"); } //ESA tag listesi if (tagName.equals("YEDEK")) { } else { HSSFRow trow = esaWb.getSheet("Tags").createRow(esaRowNr); trow.createCell(0).setCellValue(""); trow.createCell(1).setCellValue(tagName + "W"); trow.createCell(2).setCellValue("Device"); trow.createCell(3).setCellValue(modbusMasterName); trow.createCell(4).setCellValue("FC 03-16: read/write registers"); trow.createCell(5).setCellValue("Address," + Integer.toHexString(modbusOutNr)); trow.createCell(6).setCellValue("Word"); trow.createCell(7).setCellValue("False"); trow.createCell(8).setCellValue("Integer"); trow.createCell(9).setCellValue("Class_0_5: 500 msec"); trow.createCell(10).setCellValue(tagComment); trow.createCell(11).setCellValue(0); trow.createCell(12).setCellValue(""); esaRowNr++; } //ESA Scriptler if (tagName.equals("YEDEK")) { } else { esaScriptTextArea.append("\tCase " + modbusOutNr + "\n\t\tnom = \"" + tagName + "W\"\n\t\tdesc = \"" + tec(tagComment) + "\"\n\n"); } modbusOutNr++; }
From source file:ypcnv.views.impl.FileXLS.java
License:Open Source License
/** * Read data row by row and put it into model. * /*from w w w.j a v a 2 s . c o m*/ * @param headerRow * - row previous to row with real data, in fact this is row with * columns headers. * @throws ContactException */ private void insertDataToModel(HSSFRow headerRow) { HSSFSheet currentSheet = headerRow.getSheet(); int lastRowIdx = currentSheet.getLastRowNum(); int currentRowIdx = headerRow.getRowNum() + 1; for (; currentRowIdx <= lastRowIdx; currentRowIdx++) { Contact2k3 currentContact = new Contact2k3(); Boolean isVoidContact = true; for (String dataFieldKeyName : currentContact.getFieldValuesMap().keySet()) { int cellIdx = dataColumnsSequenceMap.get(dataFieldKeyName); HSSFCell cell = currentSheet.getRow(currentRowIdx).getCell(cellIdx, Row.RETURN_BLANK_AS_NULL); String cellValue = null; if (cell != null) { cellValue = getCellContent(cell); } else { cellValue = ""; } if (!cellValue.equals("")) { isVoidContact = false; } try { currentContact.setValue(dataFieldKeyName, cellValue); } catch (ContactException e) { LOG.error(String.format(FileXLSMeta.ERR_MESSAGE_NO_KEY_IN_MAP, dataFieldKeyName)); e.printStackTrace(); } } if (!isVoidContact) { dataContainer.add(currentContact); } } }
From source file:ypcnv.views.impl.FileXLS.java
License:Open Source License
/** * Insert data from model into workbook object instance. * /*from w w w . j a v a 2 s. co m*/ * @param headerRow * - row previous to row with real data, in fact this is row with * columns headers. */ private void insertDataToWorkbook(HSSFRow headerRow) { Contact2k3 currentContact; Iterator<Contact2k3> containerModelListIterator = dataContainer.getContacts().iterator(); HSSFSheet currentSheet = headerRow.getSheet(); HSSFRow currentRow; HSSFCell currentCell; int currentRowIdx = headerRow.getRowNum() + 1; int lastRowIdx = currentSheet.getLastRowNum(); int currentColumnIdx; // XXX - there is silent wipe of previous content of the sheet. for (int idx = currentRowIdx; idx <= lastRowIdx; idx++) { currentSheet.removeRow(currentSheet.getRow(idx)); } for (; containerModelListIterator.hasNext(); currentRowIdx++) { currentContact = containerModelListIterator.next(); currentSheet.createRow(currentRowIdx); currentRow = currentSheet.getRow(currentRowIdx); for (String dataFieldKeyName : dataColumnsSequenceMap.keySet()) { currentColumnIdx = dataColumnsSequenceMap.get(dataFieldKeyName); currentRow.createCell(currentColumnIdx); currentCell = currentRow.getCell(currentColumnIdx); currentCell.setCellType(Cell.CELL_TYPE_STRING); currentCell.setCellValue(currentContact.getFieldValuesMap().get(dataFieldKeyName)); } } }