List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getRow
@Override public HSSFRow getRow(int rowIndex)
From source file:com.efficio.fieldbook.web.nursery.service.impl.ExcelImportStudyServiceImpl.java
License:Open Source License
private int findRow(HSSFSheet sheet, String cellValue) { int result = 0; for (int i = 0; i < sheet.getLastRowNum(); i++) { HSSFRow row = sheet.getRow(i); if (row != null) { HSSFCell cell = row.getCell(0); if (cell != null && cell.getStringCellValue() != null) { if (cell.getStringCellValue().equals(cellValue)) { return i; }/*from w w w .j a va 2s. c o m*/ } } } return result; }
From source file:com.efficio.fieldbook.web.nursery.service.impl.ExcelImportStudyServiceImpl.java
License:Open Source License
private int findColumn(HSSFSheet sheet, String cellValue) { int result = -1; if (cellValue != null) { HSSFRow row = sheet.getRow(0); //Encabezados int cells = row.getLastCellNum(); for (int i = 0; i < cells; i++) { HSSFCell cell = row.getCell(i); if (cell.getStringCellValue().equals(cellValue)) { return i; }//from w w w . ja v a2 s . co m } } return result; }
From source file:com.elbeesee.poink.representation.HSSFCellImplementation.java
License:Open Source License
public HSSFCellImplementation(HSSFSheet aSheet, int aRowIndex, int aCellIndex) { this.mCell = aSheet.getRow(aRowIndex).getCell(aCellIndex); }
From source file:com.elbeesee.poink.representation.HSSFRowImplementation.java
License:Open Source License
public HSSFRowImplementation(HSSFSheet aSheet, int aRowIndex) { this.mRow = aSheet.getRow(aRowIndex); }
From source file:com.eryansky.core.excelTools.ExcelUtils.java
License:Apache License
public static void copySheetStyle(HSSFWorkbook destwb, HSSFSheet dest, HSSFWorkbook srcwb, HSSFSheet src) { if (src == null || dest == null) return;/*w ww .ja v a2s . c om*/ dest.setAlternativeExpression(src.getAlternateExpression()); dest.setAlternativeFormula(src.getAlternateFormula()); dest.setAutobreaks(src.getAutobreaks()); dest.setDialog(src.getDialog()); if (src.getColumnBreaks() != null) { for (int col : src.getColumnBreaks()) { dest.setColumnBreak(col); } } dest.setDefaultColumnWidth(src.getDefaultColumnWidth()); dest.setDefaultRowHeight(src.getDefaultRowHeight()); dest.setDefaultRowHeightInPoints(src.getDefaultRowHeightInPoints()); dest.setDisplayGuts(src.getDisplayGuts()); dest.setFitToPage(src.getFitToPage()); dest.setHorizontallyCenter(src.getHorizontallyCenter()); dest.setDisplayFormulas(src.isDisplayFormulas()); dest.setDisplayGridlines(src.isDisplayGridlines()); dest.setDisplayRowColHeadings(src.isDisplayRowColHeadings()); dest.setGridsPrinted(src.isGridsPrinted()); dest.setPrintGridlines(src.isPrintGridlines()); for (int i = 0; i < src.getNumMergedRegions(); i++) { CellRangeAddress r = src.getMergedRegion(i); dest.addMergedRegion(r); } if (src.getRowBreaks() != null) { for (int row : src.getRowBreaks()) { dest.setRowBreak(row); } } dest.setRowSumsBelow(src.getRowSumsBelow()); dest.setRowSumsRight(src.getRowSumsRight()); int maxcol = 0; for (int i = 0; i <= src.getLastRowNum(); i++) { HSSFRow row = src.getRow(i); if (row != null) { if (maxcol < row.getLastCellNum()) maxcol = row.getLastCellNum(); } } for (int col = 0; col <= maxcol; col++) { if (src.getColumnWidth(col) != src.getDefaultColumnWidth()) dest.setColumnWidth(col, src.getColumnWidth(col)); dest.setColumnHidden(col, src.isColumnHidden(col)); } }
From source file:com.eryansky.core.excelTools.ExcelUtils.java
License:Apache License
public static void copySheet(HSSFWorkbook destwb, HSSFSheet dest, HSSFWorkbook srcwb, HSSFSheet src) { if (src == null || dest == null) return;//from w w w. j a va2 s . c o m copySheetStyle(destwb, dest, srcwb, src); for (int i = 0; i <= src.getLastRowNum(); i++) { HSSFRow row = src.getRow(i); copyRow(destwb, dest.createRow(i), srcwb, row); } }
From source file:com.eryansky.core.excelTools.JsGridReportBase.java
License:Apache License
/** * /*from w w w . ja va 2 s . com*/ * @param * @return void */ private void generateColumn(HSSFSheet sheet, TableColumn tc, int maxlevel, int rownum, int colnum, HSSFCellStyle headerstyle) { HSSFRow row = sheet.getRow(rownum); if (row == null) row = sheet.createRow(rownum); HSSFCell cell = row.createCell(colnum); cell.setCellValue(tc.getDisplay()); if (headerstyle != null) cell.setCellStyle(headerstyle); if (tc.isComplex()) { CellRangeAddress address = new CellRangeAddress(rownum, rownum, colnum, colnum + tc.getLength() - 1); sheet.addMergedRegion(address); fillMergedRegion(sheet, address, headerstyle); int cn = colnum; for (int i = 0; i < tc.getChildren().size(); i++) { if (i != 0) { cn = cn + tc.getChildren().get(i - 1).getLength(); } generateColumn(sheet, tc.getChildren().get(i), maxlevel, rownum + 1, cn, headerstyle); } } else { CellRangeAddress address = new CellRangeAddress(rownum, rownum + maxlevel - tc.level, colnum, colnum); sheet.addMergedRegion(address); fillMergedRegion(sheet, address, headerstyle); } sheet.autoSizeColumn(colnum, true); }
From source file:com.eryansky.core.excelTools.JsGridReportBase.java
License:Apache License
/** * /*from w w w .ja va 2 s . c om*/ * @param * @return void */ private void fillMergedRegion(HSSFSheet sheet, CellRangeAddress address, HSSFCellStyle style) { for (int i = address.getFirstRow(); i <= address.getLastRow(); i++) { HSSFRow row = sheet.getRow(i); if (row == null) row = sheet.createRow(i); for (int j = address.getFirstColumn(); j <= address.getLastColumn(); j++) { HSSFCell cell = row.getCell(j); if (cell == null) { cell = row.createCell(j); if (style != null) cell.setCellStyle(style); } } } }
From source file:com.eryansky.core.excelTools.JsGridReportBase.java
License:Apache License
/** * /*w w w . java2 s . co m*/ * @param * @return void */ private void buildStyle(HSSFWorkbook wb, HSSFWorkbook src, HSSFSheet sheet, int index, HashMap<String, HSSFCellStyle> ret, String key) { HSSFRow row = sheet.getRow(index); HSSFCell cell = row.getCell(1); HSSFCellStyle nstyle = wb.createCellStyle(); ExcelUtils.copyCellStyle(wb, nstyle, src, cell.getCellStyle()); ret.put(key, nstyle); }
From source file:com.esd.cs.common.HExcelSheetParser.java
License:Open Source License
public List<List<Object>> getDatasInSheet(int sheetNumber) { List<List<Object>> result = new ArrayList<List<Object>>(); // sheet//from w w w . j ava 2s . c om HSSFSheet sheet = workbook.getSheetAt(sheetNumber); // sheet int rowCount = sheet.getLastRowNum(); logger.info("found excel rows count:" + rowCount); if (rowCount < 1) { return result; } // ??row for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { // HSSFRow row = sheet.getRow(rowIndex); if (null != row) { List<Object> rowData = new ArrayList<Object>(); // ? int cellCount = row.getLastCellNum(); // ??cell for (int cellIndex = 0; cellIndex < cellCount; cellIndex++) { HSSFCell cell = row.getCell(cellIndex); // ?? Object cellStr = this.getCellString(cell); rowData.add(cellStr); } result.add(rowData); } } return result; }