List of usage examples for org.apache.poi.ss.usermodel Row getCell
Cell getCell(int cellnum);
From source file:com.infovity.iep.loader.util.SupplierLoaderUtil.java
public static boolean rowHasData(Row row) { short cellNumber; boolean nonBlankRowFound = false; for (cellNumber = row.getFirstCellNum(); cellNumber <= row.getLastCellNum(); cellNumber++) { Cell cell = row.getCell(cellNumber); if (cell != null && row.getCell(cellNumber).getCellType() != cell.CELL_TYPE_BLANK) { nonBlankRowFound = true;/*from w ww.j a v a2 s . com*/ } } return nonBlankRowFound; }
From source file:com.inspiracode.nowgroup.scspro.xl.source.ExcelFile.java
License:Open Source License
private List<LogMessage> validateFieldNames(Sheet sheet) { List<LogMessage> result = new ArrayList<LogMessage>(); String nombreHoja = sheet.getSheetName(); String errDescription = ""; Row headingRow = sheet.getRow(HEADING_ROW); Properties prop = new Properties(); String propFileName = "excel/column_names.properties"; InputStream is = null;/*from w w w. j av a 2 s . co m*/ try { is = getClass().getClassLoader().getResourceAsStream(propFileName); if (is != null) { prop.load(is); for (int i = 1; i <= HEADING_COUNT; i++) { String expected = prop.getProperty(Integer.toString(i)); log.debug("Validando [" + Integer.toString(i) + "] validada como [" + headingRow.getCell(i - 1) + "]"); String current = headingRow.getCell(i - 1) == null || headingRow.getCell(i - 1).getStringCellValue() == null ? "" : headingRow.getCell(i - 1).getStringCellValue(); if (!expected.equals(current)) { int charValue = 64 + i; boolean aValue = false; if (charValue > 90) { charValue -= 25; aValue = true; } String columnName = aValue ? "A" : ""; columnName += Character.toString((char) charValue); errDescription = "La columna [" + nombreHoja + "]!" + columnName + " tiene el ttulo [" + current + "], " + " se esperaba: [" + expected + "]"; log.info(errDescription); result.add(new LogMessage("Validacin de encabezados", errDescription)); } else { log.debug("columna [" + expected + "] validada"); } } } else { errDescription = "Imposible abrir configuracin de campos de excel (column_names.properties)"; log.info(errDescription); result.add(new LogMessage("Validacin de encabezados", errDescription)); } } catch (Exception e) { errDescription = "Error al validar campos en la hoja [" + nombreHoja + "]: [" + e.getMessage() + "]"; log.error(errDescription, e); result.add(new LogMessage("Validacin de encabezados", errDescription)); } finally { if (is != null) { try { is.close(); } catch (Exception e) { log.error(e.getMessage(), e); } } } return result; }
From source file:com.inspiracode.nowgroup.scspro.xl.source.ExcelFile.java
License:Open Source License
private PurchaseOrder getPoFromRow(Row row) { PurchaseOrder po = new PurchaseOrder(); Company purchaser = new Company(); purchaser.setCompanyCode(getCellAsString(row.getCell(1))); purchaser.setCompanyName(row.getCell(2).getStringCellValue()); po.setPurchaser(purchaser);//from ww w. j a v a2 s . com Company seller = new Company(); seller.setCompanyCode(getCellAsString(row.getCell(3))); seller.setCompanyName(row.getCell(4).getStringCellValue()); po.setSeller(seller); Company sender = new Company(); sender.setCompanyCode(row.getCell(5).getStringCellValue()); sender.setCompanyName(row.getCell(6).getStringCellValue()); po.setSender(sender); po.setPoNumber(getCellAsString(row.getCell(7))); log.debug("PO Number: " + po.getPoNumber()); po.setPoDate(row.getCell(8).getDateCellValue()); po.setEtd(row.getCell(9).getDateCellValue()); po.setEta(row.getCell(10).getDateCellValue()); po.setSoNumber(row.getCell(11).getStringCellValue()); po.setAcceptanceDate(row.getCell(12).getDateCellValue()); Incoterms incoterm = new Incoterms(); String incotermContent = getCellAsString(row.getCell(13)); if (incotermContent.length() == 3) incoterm.setIncotermsCode(incotermContent); else incoterm.setIncotermsName(incotermContent); po.setIncoterm(incoterm); Currency currency = new Currency(); String currencyContent = getCellAsString(row.getCell(14)).trim(); if (currencyContent.length() == 3) currency.setCurrencyCode(currencyContent); else currency.setCurrencyName(currencyContent); po.setCurrency(currency); po.setSource(row.getCell(15).getStringCellValue()); PurchaseOrderType poType = new PurchaseOrderType(); poType.setPoTypeName(getCellAsString(row.getCell(16))); po.setOcType(poType); MaterialType materialType = new MaterialType(); materialType.setMaterialTypeName(getCellAsString(row.getCell(17))); po.setMaterialType(materialType); MaterialClass materialClass = new MaterialClass(); materialClass.setMaterialClassName(getCellAsString(row.getCell(18))); po.setMaterialClass(materialClass); TrafficType tt = new TrafficType(); String trafficTypeContent = getCellAsString(row.getCell(19)); if (trafficTypeContent.length() <= 2 && StringUtils.isNumeric(trafficTypeContent) && trafficTypeContent.length() > 0) tt.setTrafficTypeCode(Integer.parseInt(trafficTypeContent)); else tt.setTrafficTypeName(trafficTypeContent); po.setTrafficType(tt); Company freightForwarder = new Company(); freightForwarder.setCompanyName(getCellAsString(row.getCell(20))); TransportMode poTm = new TransportMode(); poTm.setTransportModeName(getCellAsString(row.getCell(21))); po.setTransportMode(poTm); po.setPackageQty((int) Math.ceil(row.getCell(22).getNumericCellValue())); PackageType packageType = new PackageType(); String packageTypeContent = getCellAsString(row.getCell(23)); if (packageTypeContent.length() <= 4 && !packageTypeContent.equalsIgnoreCase("DRUM")) packageType.setPackageTypeCode(packageTypeContent); else packageType.setPackageTypeName(packageTypeContent); po.setPackageType(packageType); PurchaseOrderItem item = new PurchaseOrderItem(); item.setSeqItem((int) Math.ceil(row.getCell(0).getNumericCellValue())); item.setMaterialType(materialType); item.setMaterialClass(materialClass); item.setStorage1(getCellAsString(row.getCell(24))); item.setStorage2(getCellAsString(row.getCell(25))); item.setItemNumber(getCellAsString(row.getCell(26))); Material material = new Material(); material.setPartNumber1(getCellAsString(row.getCell(27))); material.setPartNumber2(getCellAsString(row.getCell(28))); material.setDescripcionEsp(getCellAsString(row.getCell(29))); material.setDescriptionIng(getCellAsString(row.getCell(30))); material.setPurchaser(purchaser); material.setSeller(seller); item.setMaterial(material); item.setMeasureUnit(getCellAsString(row.getCell(31))); item.setOrderQuantity(row.getCell(32).getNumericCellValue()); item.setPendingQuantity(row.getCell(33).getNumericCellValue()); item.setUnitCost(row.getCell(34).getNumericCellValue()); item.setAmount(row.getCell(35).getNumericCellValue()); item.setWeightPounds(row.getCell(36).getNumericCellValue()); item.setMark(getCellAsString(row.getCell(37))); item.setModel(getCellAsString(row.getCell(38))); item.setSerie(getCellAsString(row.getCell(39))); item.setLot(getCellAsString(row.getCell(40))); item.setObservations(getCellAsString(row.getCell(41))); po.setItems(new ArrayList<PurchaseOrderItem>()); po.getItems().add(item); return po; }
From source file:com.jaredrummler.android.devices.Main.java
License:Apache License
private static List<String[]> getDeviceList(String xls) throws IOException { List<String[]> devices = new ArrayList<>(); FileInputStream fis = new FileInputStream(new File(xls)); HSSFWorkbook workbook = new HSSFWorkbook(fis); HSSFSheet sheet = workbook.getSheetAt(0); boolean firstRow = true; for (Iterator<Row> it = sheet.iterator(); it.hasNext();) { Row row = it.next(); if (firstRow) { firstRow = false;//w w w . ja v a 2 s . c om continue; // skip header row } devices.add(new String[] { getStringCellValue(row.getCell(0)), // RETAIL NAME getStringCellValue(row.getCell(1)), // MARKET NAME getStringCellValue(row.getCell(2)), // DEVICE NAME getStringCellValue(row.getCell(3)) // MODEL NAME }); } fis.close(); return devices; }
From source file:com.jaspersoft.ireport.designer.connection.gui.XlsxDataSourceConnectionEditor.java
License:Open Source License
private void jButtonGetColumnsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGetColumnsActionPerformed try {//w w w . ja va2s.c o m if (jTextFieldFilename.getText().length() > 0) { Workbook workbook = new XSSFWorkbook(new FileInputStream(new File(jTextFieldFilename.getText()))); Sheet sheet = workbook.getSheetAt(0); DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setRowCount(0); Row row = sheet.getRow(0); Map<String, Integer> columnNames = new HashMap<String, Integer>(); for (int columnIndex = 0; columnIndex < row.getLastCellNum(); columnIndex++) { Cell cell = row.getCell(columnIndex); String columnName = ""; if (cell != null) { columnName = cell.toString(); } else { columnName = "COLUMN_" + columnIndex; } if (columnName != null && columnName.trim().length() > 0) { dtm.addRow(new Object[] { columnName, new Integer(columnIndex) }); } } jTable1.updateUI(); jCheckBoxFirstRowAsHeader.setSelected(true); } } catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), I18n.getString("XlsxDataSourceConnectionEditor.Message.Exception"), JOptionPane.ERROR_MESSAGE); //"message.title.exception" } }
From source file:com.javabean.excel.ExcelDocumentReader.java
public List<String> GetColumnName(int sheetIndex) { List<String> columnNameList; Sheet sheet;/*www . j av a2 s. c o m*/ Cell cell; int columnCount; String stringTemp; sheet = GetSheet(sheetIndex); if (sheet == null) { return null; } Row row = sheet.getRow(0); columnCount = row.getLastCellNum(); columnNameList = new ArrayList(); for (int i = 0; i < columnCount; i++) { cell = row.getCell(i); stringTemp = Convert.NullToString(cell.getStringCellValue(), ReturnStringValue.NULL); columnNameList.add(stringTemp); } return columnNameList; }
From source file:com.javabean.excel.ExcelDocumentReader.java
private List<String> GetOneDataRow(Sheet sheet, int rowIndex, int columnCount) { List<String> dataRow; Cell cell;/*from w w w . j av a2 s. c o m*/ Row row; String stringTemp; dataRow = new ArrayList<>(); try { row = sheet.getRow(rowIndex); for (int i = 0; i < columnCount; i++) { cell = row.getCell(i); cell.setCellType(CELL_TYPE_STRING); if (cell == null) { stringTemp = "NULL"; } else { stringTemp = cell.getStringCellValue(); } dataRow.add(stringTemp); } } catch (Exception ex) { dataRow = null; } return dataRow; }
From source file:com.jeefuse.system.code.web.imports.excel.GsysCodeExcelImport.java
License:GNU General Public License
/** * populate model./*from w ww . ja va 2 s. c o m*/ * * @generated */ @Override protected GsysCode readExcelToModel(Row row, String[] columnNames) { if (row == null) return null; GsysCode model = new GsysCode(); int cellLenght = columnNames.length; Cell cell = null; for (int i = 0; i < cellLenght; i++) { cell = row.getCell(i); String columnName = columnNames[i]; GsysCodeField gsysCodeField = GsysCodeField.valueOfFieldLabel(columnName); if (null == gsysCodeField) { gsysCodeField = GsysCodeField.valueOfFieldName(columnName); } if (null == gsysCodeField) throw new DataNoExistException("??:" + columnName); setModelData(model, cell, gsysCodeField); InvalidValue[] invalidValues = GsysCodeValidate.validateProperty(model, gsysCodeField); if (invalidValues.length > 0) { List<String> errors = new ArrayList<String>(); for (InvalidValue invalidValue : invalidValues) { errors.add(gsysCodeField.getFieldLabel() + ": " + invalidValue.getMessage()); } throw new ValidateViolationException("" + (cell.getRowIndex() + 1) + "," + (cell.getColumnIndex() + 1) + "!", errors); } } return model; }
From source file:com.jeefuse.system.code.web.imports.excel.GsysCodevalueExcelImport.java
License:GNU General Public License
/** * populate model./*from w w w . j a v a 2 s . co m*/ * * @generated */ @Override protected GsysCodevalue readExcelToModel(Row row, String[] columnNames) { if (row == null) return null; GsysCodevalue model = new GsysCodevalue(); int cellLenght = columnNames.length; Cell cell = null; for (int i = 0; i < cellLenght; i++) { cell = row.getCell(i); String columnName = columnNames[i]; GsysCodevalueField gsysCodevalueField = GsysCodevalueField.valueOfFieldLabel(columnName); if (null == gsysCodevalueField) { gsysCodevalueField = GsysCodevalueField.valueOfFieldName(columnName); } if (null == gsysCodevalueField) throw new DataNoExistException("??:" + columnName); setModelData(model, cell, gsysCodevalueField); InvalidValue[] invalidValues = GsysCodevalueValidate.validateProperty(model, gsysCodevalueField); if (invalidValues.length > 0) { List<String> errors = new ArrayList<String>(); for (InvalidValue invalidValue : invalidValues) { errors.add(gsysCodevalueField.getFieldLabel() + ": " + invalidValue.getMessage()); } throw new ValidateViolationException("" + (cell.getRowIndex() + 1) + "," + (cell.getColumnIndex() + 1) + "!", errors); } } return model; }
From source file:com.jeefuse.system.log.web.imports.excel.GsysLoginlogExcelImport.java
License:GNU General Public License
/** * populate model./*www. j av a2 s. c om*/ * * @generated */ @Override protected GsysLoginlog readExcelToModel(Row row, String[] columnNames) { if (row == null) return null; GsysLoginlog model = new GsysLoginlog(); int cellLenght = columnNames.length; Cell cell = null; for (int i = 0; i < cellLenght; i++) { cell = row.getCell(i); String columnName = columnNames[i]; GsysLoginlogField gsysLoginlogField = GsysLoginlogField.valueOfFieldLabel(columnName); if (null == gsysLoginlogField) { gsysLoginlogField = GsysLoginlogField.valueOfFieldName(columnName); } if (null == gsysLoginlogField) throw new DataNoExistException("??:" + columnName); setModelData(model, cell, gsysLoginlogField); InvalidValue[] invalidValues = GsysLoginlogValidate.validateProperty(model, gsysLoginlogField); if (invalidValues.length > 0) { List<String> errors = new ArrayList<String>(); for (InvalidValue invalidValue : invalidValues) { errors.add(gsysLoginlogField.getFieldLabel() + ": " + invalidValue.getMessage()); } throw new ValidateViolationException("" + (cell.getRowIndex() + 1) + "," + (cell.getColumnIndex() + 1) + "!", errors); } } return model; }