List of usage examples for org.apache.poi.hssf.usermodel HSSFRow getCell
@Override public HSSFCell getCell(int cellnum)
From source file:com.dv.util.DVExcelIO.java
License:Open Source License
public static Vector<Vector> readExcelReturnArrayList(String fileName, String sheetName, int rowCount) { Vector<Vector> hm = new Vector<Vector>(); File file = new File(fileName); FileInputStream in = null;/* www . j a v a2 s .co m*/ try { in = new FileInputStream(file); HSSFWorkbook workbook = new HSSFWorkbook(in); HSSFSheet sheet = workbook.getSheet(sheetName); HSSFRow row = null; HSSFCell cell = null; for (int i = 0; i < rowCount; i = i + 3) { Vector cellList = new Vector(); row = sheet.getRow((short) i); if (row != null) { cell = row.getCell(0); String cellString = cell.toString().replace(".0", " ").trim(); cellString = cellString.replace("\n", " ").trim(); cellList.add(0, cellString); } row = sheet.getRow((short) i + 1); if (row != null) { cell = row.getCell(0); String cellString = cell.toString().replace(".0", " ").trim(); cellString = cellString.replace("\n", " ").trim(); cellList.add(1, cellString); } row = sheet.getRow((short) i + 2); if (row != null) { cell = row.getCell(0); String cellString = cell.toString().replace(".0", " ").trim(); cellString = cellString.replace("\n", " ").trim(); cellList.add(2, cellString); } hm.addElement(cellList); } } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e1) { } } } return hm; }
From source file:com.dv.util.DVExcelIO.java
License:Open Source License
public static Vector setExcelBHTIMFormat(String fullExcelFileName, String sheetName, int rowNumbers) { File file = new File(fullExcelFileName); FileInputStream in = null;//from w w w . j ava2 s.c om Vector cols = new Vector(); try { in = new FileInputStream(file); HSSFWorkbook workbook = new HSSFWorkbook(in); HSSFSheet sheet = workbook.getSheet(sheetName); HSSFRow row = null; HSSFCell cell = null; for (int i = 2; i < rowNumbers; i++) { row = sheet.getRow(i); cell = row.getCell(4);//9 for cty String ppp = cell.toString().trim(); cell = row.getCell(9); String fff = cell.toString().trim(); if (!ppp.equals("")) { String contents = "Verify from FMS side for " + ppp + "(" + fff + ")"; // cols.addElement(contents); row.getCell(16).setCellValue(contents); } else { return null; } } FileOutputStream fOut = new FileOutputStream(file); workbook.write(fOut); fOut.flush(); fOut.close(); } catch (Exception eee) { } return cols; }
From source file:com.efficio.fieldbook.web.nursery.service.impl.ExcelImportStudyServiceImpl.java
License:Open Source License
private void importDataToWorkbook(HSSFWorkbook xlsBook, Workbook workbook) { if (workbook.getObservations() != null) { HSSFSheet observationSheet = xlsBook.getSheetAt(1); int xlsRowIndex = 1; //row 0 is the header row for (MeasurementRow wRow : workbook.getObservations()) { HSSFRow xlsRow = observationSheet.getRow(xlsRowIndex); for (MeasurementData wData : wRow.getDataList()) { String label = wData.getLabel(); int xlsColIndex = findColumn(observationSheet, label); Cell cell = xlsRow.getCell(xlsColIndex); String xlsValue = ""; if (cell != null) { if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { Double doubleVal = Double.valueOf(cell.getNumericCellValue()); Integer intVal = Integer.valueOf(doubleVal.intValue()); if (Double.parseDouble(intVal.toString()) == doubleVal.doubleValue()) { xlsValue = intVal.toString(); } else { xlsValue = doubleVal.toString(); }//from ww w . j a v a2 s . co m } else xlsValue = cell.getStringCellValue(); } wData.setValue(xlsValue); } xlsRowIndex++; } } }
From source file:com.efficio.fieldbook.web.nursery.service.impl.ExcelImportStudyServiceImpl.java
License:Open Source License
private void validateRowIdentifiers(HSSFSheet observationSheet, Workbook workbook) throws WorkbookParserException { if (workbook.getObservations() != null) { String gidLabel = getColumnLabel(workbook, TermId.GID.getId()); String desigLabel = getColumnLabel(workbook, TermId.DESIG.getId()); String entryLabel = getColumnLabel(workbook, TermId.ENTRY_NO.getId()); int gidCol = findColumn(observationSheet, gidLabel); int desigCol = findColumn(observationSheet, desigLabel); int entryCol = findColumn(observationSheet, entryLabel); int rowIndex = 1; for (MeasurementRow wRow : workbook.getObservations()) { HSSFRow row = observationSheet.getRow(rowIndex++); Integer gid = getMeasurementDataValueInt(wRow, gidLabel); String desig = getMeasurementDataValue(wRow, desigLabel); Integer entry = getMeasurementDataValueInt(wRow, entryLabel); Integer xlsGid = getExcelValueInt(row, gidCol); String xlsDesig = row.getCell(desigCol).getStringCellValue(); Integer xlsEntry = getExcelValueInt(row, entryCol); if (gid == null || desig == null || entry == null || xlsDesig == null || !gid.equals(xlsGid) || !desig.trim().equalsIgnoreCase(xlsDesig.trim()) || !entry.equals(xlsEntry)) { throw new WorkbookParserException("error.workbook.import.observationRowMismatch"); }/*ww w . ja v a2 s.c o m*/ } } }
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 ww . j a va 2 s .c om*/ } } } 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 ww . j a v a2 s .c om*/ } } return result; }
From source file:com.efficio.fieldbook.web.nursery.service.impl.ExcelImportStudyServiceImpl.java
License:Open Source License
private Integer getExcelValueInt(HSSFRow row, int columnIndex) { Cell cell = row.getCell(columnIndex); String xlsStr = ""; if (cell.getCellType() == Cell.CELL_TYPE_STRING) xlsStr = cell.getStringCellValue(); else//from w w w . j a v a 2 s . c o m xlsStr = String.valueOf((int) cell.getNumericCellValue()); if (NumberUtils.isNumber(xlsStr)) { return Integer.valueOf(xlsStr); } return null; }
From source file:com.elbeesee.poink.representation.HSSFCellImplementation.java
License:Open Source License
public HSSFCellImplementation(HSSFRow aRow, int aCellIndex) { this.mCell = aRow.getCell(aCellIndex); }
From source file:com.eryansky.core.excelTools.ExcelUtils.java
License:Apache License
public static void copyRow(HSSFWorkbook destwb, HSSFRow dest, HSSFWorkbook srcwb, HSSFRow src) { if (src == null || dest == null) return;/*from w ww . j a va 2 s . c o m*/ for (int i = 0; i <= src.getLastCellNum(); i++) { if (src.getCell(i) != null) { HSSFCell cell = dest.createCell(i); copyCell(destwb, cell, srcwb, src.getCell(i)); } } }
From source file:com.eryansky.core.excelTools.JsGridReportBase.java
License:Apache License
/** * //from www. j a v a 2 s . c o m * @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); } } } }