List of usage examples for org.apache.poi.ss.usermodel Cell getStringCellValue
String getStringCellValue();
For numeric cells we throw an exception.
From source file:com.asakusafw.testdriver.excel.DefaultExcelRuleExtractor.java
License:Apache License
private String getStringCell(Row row, RuleSheetFormat item) throws FormatException { assert row != null; assert item != null; Cell cell = row.getCell(item.getColumnIndex()); if (cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK) { return ""; //$NON-NLS-1$ } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) { return cell.getStringCellValue(); }/*from w w w . j a v a 2 s .c om*/ throw new FormatException( MessageFormat.format(Messages.getString("DefaultExcelRuleExtractor.errorInvalidStringCell"), //$NON-NLS-1$ item.getTitle(), cell.getRowIndex() + 1, cell.getColumnIndex() + 1)); }
From source file:com.asakusafw.testdriver.excel.ExcelSheetDataModelSource.java
License:Apache License
private Map<PropertyName, Integer> extractProperties() throws IOException { // first row must be property names Row row = sheet.getRow(0);/*from w ww. j a v a 2 s . c om*/ if (row == null) { throw new IOException( MessageFormat.format(Messages.getString("ExcelSheetDataModelSource.errorInvalidHeader"), //$NON-NLS-1$ id)); } nextRowNumber = 1; Map<PropertyName, Integer> results = new LinkedHashMap<>(); for (Iterator<Cell> iter = row.cellIterator(); iter.hasNext();) { Cell cell = iter.next(); int type = cell.getCellType(); if (type == Cell.CELL_TYPE_BLANK) { continue; } if (type != Cell.CELL_TYPE_STRING || cell.getStringCellValue().isEmpty()) { throw new IOException( MessageFormat.format(Messages.getString("ExcelSheetDataModelSource.errorInvalidHeaderCell"), //$NON-NLS-1$ id, cell.getColumnIndex() + 1)); } String name = cell.getStringCellValue(); PropertyName property = toPropertyName(cell, name); if (definition.getType(property) == null) { throw new IOException( MessageFormat.format(Messages.getString("ExcelSheetDataModelSource.errorMissingProperty"), //$NON-NLS-1$ definition.getModelClass().getName(), property, id, cell.getColumnIndex() + 1)); } results.put(property, cell.getColumnIndex()); } if (results.isEmpty()) { throw new IOException( MessageFormat.format(Messages.getString("ExcelSheetDataModelSource.errorEmptyProperty"), //$NON-NLS-1$ id)); } return results; }
From source file:com.asakusafw.testdriver.excel.legacy.LegacyExcelRuleExtractor.java
License:Apache License
private String getStringCell(Sheet sheet, int rowIndex, int colIndex) { assert sheet != null; Row row = sheet.getRow(rowIndex);/* w w w. j a v a 2 s. c o m*/ if (row == null) { return null; } Cell cell = row.getCell(colIndex); if (cell == null || cell.getCellType() != Cell.CELL_TYPE_STRING) { return null; } return cell.getStringCellValue(); }
From source file:com.asakusafw.testdriver.excel.legacy.LegacyExcelRuleExtractor.java
License:Apache License
@Override public String extractName(Row row) throws FormatException { if (row == null) { throw new IllegalArgumentException("row must not be null"); //$NON-NLS-1$ }//from w w w. j ava 2 s . c o m // strict checking for cell type Cell cell = row.getCell(ConditionSheetItem.COLUMN_NAME.getCol()); if (cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK) { return null; } else if (cell.getCellType() != Cell.CELL_TYPE_STRING) { throw new FormatException(MessageFormat.format( Messages.getString("LegacyExcelRuleExtractor.errorInvalidNameType"), //$NON-NLS-1$ ConditionSheetItem.COLUMN_NAME.getName(), cell.getRowIndex() + 1, cell.getColumnIndex() + 1)); } String name = cell.getStringCellValue(); if (name.isEmpty()) { return null; } return name.toLowerCase(); }
From source file:com.asakusafw.testdriver.excel.legacy.LegacyExcelRuleExtractor.java
License:Apache License
private String getStringCell(Row row, ConditionSheetItem item) throws FormatException { assert row != null; assert item != null; Cell cell = row.getCell(item.getCol()); if (cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK) { return ""; //$NON-NLS-1$ } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) { return cell.getStringCellValue(); }//w w w . j a va 2 s. c o m throw new FormatException( MessageFormat.format(Messages.getString("LegacyExcelRuleExtractor.errorInvalidStringCell"), //$NON-NLS-1$ item.getName(), cell.getRowIndex() + 1, cell.getColumnIndex() + 1)); }
From source file:com.aurel.track.lucene.util.poi.XLSTextStripper.java
License:Open Source License
public XLSTextStripper(FileInputStream fis, String fileExtension) { try {/*from w w w . j ava 2s .co m*/ StringBuffer sb = new StringBuffer(); Workbook workbook = null; if (LuceneFileExtractor.INDEXABLE_EXTENSIONS.XLS.equalsIgnoreCase(fileExtension)) { workbook = new HSSFWorkbook(fis); } else { if (LuceneFileExtractor.INDEXABLE_EXTENSIONS.XLSX.equalsIgnoreCase(fileExtension)) { workbook = new XSSFWorkbook(fis); } } if (workbook != null) { int numOfSheets = workbook.getNumberOfSheets(); for (int i = 0; i < numOfSheets; i++) { Sheet sheet = workbook.getSheetAt(i); Iterator<Row> rowIterator = sheet.rowIterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); String cellStringValue = null; if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { boolean booleanValue = cell.getBooleanCellValue(); cellStringValue = Boolean.toString(booleanValue); } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { double doubleValue = cell.getNumericCellValue(); cellStringValue = Double.toString(doubleValue); } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) { cellStringValue = cell.getStringCellValue(); } if (cellStringValue != null) { sb.append(cellStringValue); sb.append("\t"); } } sb.append("\n"); } } } _text = sb.toString(); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } }
From source file:com.avaya.plds.excel.ExcelRead.java
public List<String> getPoeticFeatureLoad(String value1, String value2, int sheetNo, int headers) { System.out.println(" Inside of getPoeticFeatureLoad method ..."); sheet = xssfWorkbook.getSheetAt(sheetNo); boolean read = false; List<String> dataList = new ArrayList<String>(); rowIterator = sheet.iterator();// ww w . ja va2s . c om while (rowIterator.hasNext()) { StringBuilder builder = new StringBuilder(); Row row = rowIterator.next(); int rowNumber = row.getRowNum(); if (row != null) { for (short i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { if (row.getCell(i) != null && (row.getCell(i).getCellType() == row.getCell(i).CELL_TYPE_STRING) && row.getCell(i).getStringCellValue().contains(value1) && i == 0) { read = true; break; //builder.append(value1).append("\t"); } else if (row.getCell(i) != null && (row.getCell(i).getCellType() == row.getCell(i).CELL_TYPE_STRING) && row.getCell(i).getStringCellValue().contains(value2)) { read = false; } else if (read) { // System.out.println("rowNumber "+ rowNumber); maxCellIndex = (row.getLastCellNum() > maxCellIndex && rowNumber > 0) ? row.getLastCellNum() : maxCellIndex; // System.out.println("maxCellIndex "+ maxCellIndex); Cell cell = row.getCell(i); if (cell != null) { if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { //if(i >0) builder.append( cell != null ? Double.valueOf(cell.getNumericCellValue()).longValue() : "") .append("\t"); } else { //if(i >0 ) builder.append(cell != null ? cell.getStringCellValue() : "").append("\t"); } } else { //if(i >0) builder.append("").append("\t"); } } if (headers == rowNumber) { //if(i>0) builder.append(row.getCell(i).getStringCellValue()).append("\t"); } } if (!builder.toString().equals("") && !builder.toString().matches("^ null.*")) dataList.add(builder.toString().replaceFirst(",", "")); } } return dataList; }
From source file:com.avaya.plds.excel.ExcelRead.java
public List<String> getPoeticProductFamily() { System.out.println(" Inside of getPoeticProductFamily "); sheet = xssfWorkbook.getSheetAt(3);/* w ww .j ava2s .c om*/ List<String> family = new ArrayList<String>(); List<String> familyCodes = new ArrayList<String>(); List<String> pld = new ArrayList<String>(); // pld product line description List<String> plc = new ArrayList<String>(); // plc product line code rowIterator = sheet.iterator(); int count = 0; int appCodeCount = 0; int appNameCount = 0; boolean status = false; while (rowIterator.hasNext()) { Row row = rowIterator.next(); cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { if (cell.getStringCellValue().equals("NEW FAMILY Configurations")) { status = true; count++; } else if (cell.getStringCellValue().equals("NPI Pre-Configuration Data only")) { status = true; count += 2; appCodeCount = 0; appNameCount = 0; System.out.println("cell value : tetsing " + cell.getStringCellValue()); } else if (count > 3 && count < 6) { if (count == 4) { family.add(cell.getStringCellValue().trim()); } else { familyCodes.add(cell.getStringCellValue().trim()); } System.out.print(cell.getStringCellValue() + "\t"); } else if (count == 6) { status = false; } else if (count > 9 && count < 12) { if (count == 10) { if (appNameCount < 2) { pld.add(cell.getStringCellValue()); appNameCount++; } } else { if (appCodeCount < 2) { plc.add(cell.getStringCellValue()); appCodeCount++; } } } } } if (status) { count++; } } this.storeMap(family, familyCodes, 0); this.storeMap(pld, plc, 1); for (String key : getProductFamilyListValueMap.keySet()) { System.out.println("key = " + key + " and value =" + getProductFamilyListValueMap.get(key)); } for (String key : getApplicationListValueMap.keySet()) { System.out.println("key = " + key + " and value =" + getApplicationListValueMap.get(key)); } return null; }
From source file:com.axelor.apps.admin.service.ViewDocExportService.java
License:Open Source License
public static String getCellValue(Cell cell) { if (cell != null) { return cell.getStringCellValue(); }/*from w w w .j av a2 s . c o m*/ return null; }
From source file:com.axelor.studio.service.data.validator.ValidatorService.java
License:Open Source License
public void addLog(String log, String sheetName, int rowNum) throws IOException { if (logFile == null) { logFile = File.createTempFile("ImportLog", ".xlsx"); logBook = new XSSFWorkbook(); }//from w w w .ja v a 2 s.c o m XSSFSheet sheet = logBook.getSheet(sheetName); if (sheet == null) { sheet = logBook.createSheet(sheetName); XSSFRow titleRow = sheet.createRow(0); titleRow.createCell(0).setCellValue("Row Number"); titleRow.createCell(1).setCellValue("Issues"); } Iterator<Row> rowIterator = sheet.rowIterator(); Row logRow = null; while (rowIterator.hasNext()) { Row sheetRow = rowIterator.next(); Cell cell = sheetRow.getCell(0); if (cell.getCellType() != Cell.CELL_TYPE_NUMERIC) { continue; } double value = cell.getNumericCellValue(); if (value == rowNum + 1) { logRow = sheetRow; break; } } if (logRow == null) { logRow = sheet.createRow(sheet.getPhysicalNumberOfRows()); } Cell cell = logRow.getCell(0); if (cell == null) { cell = logRow.createCell(0); cell.setCellValue(rowNum + 1); } cell = logRow.getCell(1); if (cell == null) { cell = logRow.createCell(1); } String oldValue = cell.getStringCellValue(); if (oldValue == null) { cell.setCellValue(log); } else { cell.setCellValue(oldValue + "\n" + log); } }