List of usage examples for org.apache.poi.hssf.usermodel HSSFRow getRowNum
@Override public int getRowNum()
From source file:com.bayareasoftware.chartengine.ds.ExcelDataStream.java
License:Apache License
private Object[] getRowData(HSSFRow row, Metadata md) { evaluator.setCurrentRow(row); // Workaround for forumula evaluator bug Object[] data = new Object[md.getColumnCount()]; int i = 0;//from ww w . j a v a 2s .co m for (i = 0; i < data.length; i++) { int type = md.getColumnType(i + 1); HSSFCell c = row.getCell((short) i); try { data[i] = getCellData(c, row.getRowNum(), type, i + 1); } catch (NumberFormatException nfe) { /* convert invalid numerics to null. This is also * needed with blank cells. */ } } return data; }
From source file:com.bayareasoftware.chartengine.ds.util.ExcelDump.java
License:Apache License
private static String row2string(HSSFRow r, int maxCell) { if (r == null) { return ""; }/* w w w . j a v a2 s . c o m*/ StringBuilder sb = new StringBuilder(); sb.append("<tr>"); sb.append("<td>#<b>" + r.getRowNum() + "</b> phys=" + r.getPhysicalNumberOfCells() + "<br/>1st=" + r.getFirstCellNum() + " last=" + r.getLastCellNum() + "</td>"); for (short i = 0; i < maxCell; i++) { HSSFCell c = r.getCell(i); sb.append("<td>" + cell2string(c) + "</td>"); } sb.append("</tr>\n"); return sb.toString(); }
From source file:com.bayareasoftware.chartengine.ds.util.ExcelInference.java
License:Apache License
private void inferMetadata() { datarow = getDataRowNum();/* ww w . j av a 2s. c om*/ if (datarow == -1) { // can't figure out anything - go braindead datarow = 1; headerrow = 0; metadata = getBraindeadMetadata(); } else { /*p("inferred data row=" + datarow + " cell=" + getCellString(sheet.getRow(datarow).getCell(2)) + " cell(0,0)=" + getCellString(sheet.getRow(0).getCell(0))); */ metadata = getMetadata(sheet.getRow(datarow)); HSSFRow titleRow = inferHeaderRow(datarow); if (titleRow != null) { headerrow = titleRow.getRowNum(); fillColumnNames(titleRow); } } // make a more laborious guess at column types that are unknown... for (int i = 1; i <= metadata.getColumnCount(); i++) { if (metadata.getColumnType(i) == UNKNOWN) { metadata.setColumnType(i, this.inferColumnType(sheet, datarow, i - 1)); } if (metadata.getColumnName(i) == null) { metadata.setColumnName(i, "col" + i); } } }
From source file:com.cedarsoft.utils.excel.SpreadSheetColumnMapping.java
License:Open Source License
@Nonnull public T getValue(@Nonnull HSSFRow row) throws NoValueFoundException { HSSFCell cell = row.getCell(getIndex()); if (cell == null) { throw new NoValueFoundException("No cell found at index " + getIndex() + " for row " + row.getRowNum()); }/*from w w w . ja va 2s . c o m*/ return getValue(cell); }
From source file:com.cms.utils.ExcelReader.java
public static void copyRow(HSSFSheet srcSheet, HSSFSheet destSheet, HSSFRow srcRow, HSSFRow destRow, Map<Integer, HSSFCellStyle> styleMap) { Set<CellRangeAddress> mergedRegions = new TreeSet<CellRangeAddress>(); destRow.setHeight(srcRow.getHeight()); for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) { HSSFCell oldCell = srcRow.getCell(j); HSSFCell newCell = destRow.getCell(j); if (oldCell != null) { if (newCell == null) { newCell = destRow.createCell(j); }/* ww w .ja va 2 s .com*/ copyCell(oldCell, newCell, styleMap); CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex()); if (mergedRegion != null) { CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.getFirstRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastRow(), mergedRegion.getLastColumn()); if (isNewMergedRegion(newMergedRegion, mergedRegions)) { mergedRegions.add(newMergedRegion); destSheet.addMergedRegion(newMergedRegion); } } } } }
From source file:com.codecrate.shard.transfer.excel.AbstractExcelRowHandler.java
License:Apache License
/** * * @param row//from w w w. ja v a 2 s .c o m * @param column zero indexed column number * @return */ protected String getStringFromRow(HSSFRow row, int column) { HSSFCell nameCell = row.getCell((short) column); if (null == nameCell) { LOG.info("No string value found for [row, column]: " + row.getRowNum() + ", " + column); return null; } return nameCell.getStringCellValue(); }
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()); vRowXML.append("\" sheetIndex=\""); vRowXML.append(vRow.getSheet().getWorkbook().getSheetIndex(vSheetName)); vRowXML.append("\">"); // do the cells int i = 0;/*from www .ja va2 s .co m*/ 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.eryansky.core.excelTools.JsGridReportBase.java
License:Apache License
/** * ?/*from w w w . ja v a 2s . c om*/ * * @param * @return void */ private void createCell(HSSFRow row, TableColumn tc, List<TableDataCell> data, int i, int index, HashMap<String, HSSFCellStyle> styles) { TableDataCell dc = data.get(i); HSSFCell cell = row.createCell(index); switch (tc.getColumnType()) { case TableColumn.COLUMN_TYPE_INTEGER: cell.setCellValue(dc.getIntValue()); HSSFCellStyle style = styles.get("INT"); if (row.getRowNum() % 2 != 0) style = styles.get("INT_C"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_FLOAT_2: cell.setCellValue(dc.getDoubleValue()); style = styles.get("D2"); if (row.getRowNum() % 2 != 0) style = styles.get("D2_C"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_FLOAT_3: cell.setCellValue(dc.getDoubleValue()); style = styles.get("D3"); if (row.getRowNum() % 2 != 0) style = styles.get("D3_C"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_RED_BG: cell.setCellValue(dc.getValue()); style = styles.get("RED_BG"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_YELLOW_BG: cell.setCellValue(dc.getValue()); style = styles.get("YELLOW_BG"); if (style != null) cell.setCellStyle(style); break; case TableColumn.COLUMN_TYPE_GREEN_BG: cell.setCellValue(dc.getValue()); style = styles.get("GREEN_BG"); if (style != null) cell.setCellStyle(style); break; default: if (dc.getValue().equalsIgnoreCase(" ")) cell.setCellValue(""); else cell.setCellValue(dc.getValue()); style = styles.get("STRING"); if (row.getRowNum() % 2 != 0) style = styles.get("STRING_C"); if (style != null) cell.setCellStyle(style); } }
From source file:com.googlecode.bdoc.testsupport.excel.ExcelExampleTable.java
License:Open Source License
/** * Gets cell values from row//from w ww . j a v a 2 s . c o m * * @param relativRowIndex * to the description and cell headers * @return cell values for the given row */ public List<Object> getRow(int relativRowIndex) { List<Object> result = new ArrayList<Object>(); HSSFRow row = sheet.getRow(startingRowIndex + 2 + relativRowIndex); for (int cellnum = 0; cellnum < row.getLastCellNum(); cellnum++) { HSSFCell cell = row.getCell(cellnum); try { int cellType = cell.getCellType(); switch (cellType) { case HSSFCell.CELL_TYPE_NUMERIC: { result.add(cell.getNumericCellValue()); continue; } case HSSFCell.CELL_TYPE_FORMULA: { result.add(cell.getNumericCellValue()); continue; } case HSSFCell.CELL_TYPE_STRING: { result.add(cell.getRichStringCellValue().getString()); continue; } default: { throw new IllegalStateException("can't handle value"); } } } catch (Exception e) { throw new ExcelTableCellReadException(row.getRowNum() + 1, cellnum, cell, e); } } return result; }
From source file:com.haulmont.mp2xls.writer.LocalizationBatchExcelWriter.java
License:Apache License
public static void exportToXls(LocalizationsBatch localizations, String outputXls) throws IOException { FileOutputStream fileOut = new FileOutputStream(outputXls); HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet worksheet = workbook.createSheet("localizations"); HSSFCellStyle systemStyle = workbook.createCellStyle(); systemStyle.setFillForegroundColor(HSSFColor.RED.index); systemStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFRow row = worksheet.createRow(0); row.createCell(0).setCellValue("Project path"); row.createCell(1).setCellValue(localizations.getProjectDirectory()); HSSFRow headLine = worksheet.createRow(5); headLine.createCell(0).setCellValue("Path to File"); headLine.createCell(1).setCellValue("Parameter Name"); Map<String, Integer> localeColumn = new HashMap<>(); int colCount = 1; for (String localeId : localizations.getLocalizationIds()) { if (localizations.getScanLocalizationIds().contains(localeId == null ? "en" : localeId)) { String id = localeId == null ? "default" : localeId; headLine.createCell(++colCount).setCellValue(id); localeColumn.put(localeId, colCount); }/*from ww w . ja v a 2 s.c o m*/ } Integer currentRow = headLine.getRowNum(); for (String folder : localizations.getMessagesLocalizations().keySet()) { Set<MessagesLocalization> locales = localizations.getMessagesLocalizations().get(folder); Set<String> parameters = new HashSet<>(); for (MessagesLocalization locale : locales) { if (localizations.getScanLocalizationIds() .contains(locale.getLocaleId() == null ? "en" : locale.getLocaleId())) parameters.addAll(locale.getMessages().keySet()); } for (String parameter : parameters) { row = worksheet.createRow(++currentRow); HSSFCell cell = row.createCell(0); cell.setCellValue(folder); if (MessagesFolderReader.systemKeys.contains(parameter)) { cell.setCellStyle(systemStyle); row.setZeroHeight(true); } cell = row.createCell(1); cell.setCellValue(parameter); if (MessagesFolderReader.systemKeys.contains(parameter)) { cell.setCellStyle(systemStyle); } for (MessagesLocalization locale : locales) { if (localizations.getScanLocalizationIds() .contains(locale.getLocaleId() == null ? "en" : locale.getLocaleId())) { Integer columnNum = localeColumn.get(locale.getLocaleId()); cell = row.createCell(columnNum); cell.setCellValue(locale.getMessages().get(parameter)); } } } } worksheet.setAutoFilter(new CellRangeAddress(headLine.getRowNum(), worksheet.getLastRowNum(), 0, colCount)); worksheet.createFreezePane(0, headLine.getRowNum() + 1); /* for (int i = 0; i < colCount; i++){ worksheet.autoSizeColumn(i); worksheet.setColumnWidth(i, worksheet.getColumnWidth(i) + 100); } */ workbook.write(fileOut); fileOut.flush(); fileOut.close(); }