List of usage examples for org.apache.poi.ss.usermodel CellType BLANK
CellType BLANK
To view the source code for org.apache.poi.ss.usermodel CellType BLANK.
Click Source Link
From source file:addCE.ExcelReader.java
public void read() { try {// w w w.j a v a2 s. com FileInputStream excelFile = new FileInputStream(new File(excelFileName)); Workbook workbook = new XSSFWorkbook(excelFile); Sheet datatypeSheet = workbook.getSheetAt(0); Iterator<Row> iterator = datatypeSheet.iterator(); iterator.next(); iterator.next(); iterator.next(); while (iterator.hasNext()) { Row currentRow = iterator.next(); ArrayList<String> data = new ArrayList<String>(); Iterator<Cell> cellIterator = currentRow.iterator(); while (cellIterator.hasNext()) { Cell currentCell = cellIterator.next(); //getCellTypeEnum shown as deprecated for version 3.15 //getCellTypeEnum will be renamed to getCellType starting from version 4.0 if (currentCell == null || currentCell.getCellTypeEnum() == CellType.BLANK) { data.add("None"); } else if (currentCell.getCellTypeEnum() == CellType.STRING) { data.add(currentCell.getStringCellValue()); //System.out.print(currentCell.getStringCellValue() + "--"); } else if (currentCell.getCellTypeEnum() == CellType.NUMERIC) { data.add(Double.toString(currentCell.getNumericCellValue())); //System.out.print(currentCell.getNumericCellValue() + "--"); } } this.attendees.add(data); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:cn.edu.zjnu.acm.judge.util.excel.ExcelUtil.java
License:Apache License
private static void create(Stream<?> stream, Row row) { AtomicInteger counter = new AtomicInteger(); stream.forEach(value -> {/*from w ww .j ava 2s . c om*/ if (value != null) { if (value instanceof String) { row.createCell(counter.getAndIncrement(), CellType.STRING).setCellValue((String) value); } else if (value instanceof Number) { row.createCell(counter.getAndIncrement(), CellType.NUMERIC) .setCellValue(((Number) value).doubleValue()); } else if (value instanceof Boolean) { row.createCell(counter.getAndIncrement(), CellType.BOOLEAN).setCellValue((Boolean) value); } else if (value instanceof Date) { row.createCell(counter.getAndIncrement(), CellType.NUMERIC).setCellValue((Date) value); } else if (value instanceof Calendar) { row.createCell(counter.getAndIncrement(), CellType.NUMERIC).setCellValue((Calendar) value); } else { row.createCell(counter.getAndIncrement(), CellType.ERROR); } } else { row.createCell(counter.getAndIncrement(), CellType.BLANK); } }); }
From source file:com.ebay.xcelite.writer.SheetWriterAbs.java
License:Apache License
protected void writeToCell(Cell cell, Object fieldValueObj, Class<?> dataType) { cell.setCellStyle(CellStylesBank.get(sheet.getNativeSheet().getWorkbook()).getBoldStyle()); if (fieldValueObj == null) { cell.setCellType(CellType.BLANK); cell.setCellValue(""); } else {/* ww w . j a v a 2 s . co m*/ Class<?> type = fieldValueObj.getClass(); if (dataType != null) { type = dataType; } if (type == Date.class) { cell.setCellValue((Date) fieldValueObj); } else if (type == Boolean.class) { cell.setCellValue((Boolean) fieldValueObj); } else if (type == Double.class || type == double.class || type == Integer.class || type == int.class || type == Long.class || type == long.class || type == Float.class || type == float.class || type == Short.class || type == short.class) { cell.setCellType(CellType.NUMERIC); cell.setCellValue(Double.valueOf(fieldValueObj.toString())); } else { cell.setCellType(CellType.STRING); cell.setCellValue(fieldValueObj.toString()); } } }
From source file:com.ostrichemulators.semtool.poi.main.xlsxml.LoadingSheetXmlHandler.java
@Override public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { if (null != name) { switch (name) { case "row": rownum = Integer.parseInt(attributes.getValue("r")) - 1; currentrowdata.clear();/* w w w .j ava 2s . c o m*/ break; case "c": // c is a new cell String celltypestr = attributes.getValue("t"); celltype = (formats.containsKey(celltypestr) ? formats.get(celltypestr) : CellType.BLANK); // dates don't always have a type attribute if (CellType.NUMERIC == celltype || null == celltypestr) { celltype = CellType.NUMERIC; // check if it's a date String styleidstr = attributes.getValue("s"); int styleid = (null == styleidstr ? 0 : Integer.parseInt(styleidstr)); XSSFCellStyle style = styles.getStyleAt(styleid); int formatIndex = style.getDataFormat(); String formatString = style.getDataFormatString(); isdate = DateUtil.isADateFormat(formatIndex, formatString); } String colname = attributes.getValue("r"); colnum = getColNum(colname.substring(0, colname.lastIndexOf(Integer.toString(rownum + 1)))); break; case "v": // new value for a cell setReading(true); resetContents(); break; } } }
From source file:com.ostrichemulators.semtool.poi.main.xlsxml.MetadataTabXmlHandler.java
@Override public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { if (null != name) { switch (name) { case "row": rownum = Integer.parseInt(attributes.getValue("r")) - 1; currentrowdata.clear();/*from w w w .ja v a2s . c o m*/ break; case "c": // c is a new cell String celltypestr = attributes.getValue("t"); celltype = (formats.containsKey(celltypestr) ? formats.get(celltypestr) : CellType.BLANK); String colname = attributes.getValue("r"); colnum = LoadingSheetXmlHandler .getColNum(colname.substring(0, colname.lastIndexOf(Integer.toString(rownum + 1)))); break; case "v": // new value for a cell setReading(true); resetContents(); break; } } }
From source file:com.streamsets.pipeline.lib.parser.excel.WorkbookParser.java
License:Apache License
private boolean rowIsBlank(Row row) { // returns true if a row has cells but all cells are 'BLANK' type. boolean isBlank = true; for (int columnNum = row.getFirstCellNum(); columnNum < row.getLastCellNum(); columnNum++) { Cell c = row.getCell(columnNum); isBlank = isBlank && (c == null || c.getCellTypeEnum() == CellType.BLANK); if (!isBlank) break; }// www . j a v a2 s.co m return isBlank; }
From source file:de.jlo.talendcomp.excel.SpreadsheetInput.java
License:Apache License
private String getStringCellValue(Cell cell, int originalColumnIndex) throws Exception { String value = null;/*from w w w. jav a2 s .c o m*/ if (cell != null) { CellType cellType = cell.getCellTypeEnum(); if (cellType == CellType.FORMULA) { try { value = getDataFormatter().formatCellValue(cell, getFormulaEvaluator()); } catch (Exception e) { if (useCachedValuesForFailedEvaluations) { cellType = cell.getCachedFormulaResultTypeEnum(); if (cellType == CellType.STRING) { if (returnURLInsteadOfName) { Hyperlink link = cell.getHyperlink(); if (link != null) { if (concatenateLabelUrl) { String url = link.getAddress(); if (url == null) { url = ""; } String label = link.getLabel(); if (label == null) { label = ""; } value = label + "|" + url; } else { value = link.getAddress(); } } else { value = cell.getStringCellValue(); } } else { value = cell.getStringCellValue(); } } else if (cellType == CellType.NUMERIC) { if (DateUtil.isCellDateFormatted(cell)) { if (defaultDateFormat != null) { Date d = cell.getDateCellValue(); if (d != null) { value = defaultDateFormat.format(d); } } else { value = getDataFormatter().formatCellValue(cell); } } else { if (overrideExcelNumberFormat) { value = getNumberFormat(originalColumnIndex).format(cell.getNumericCellValue()); } else { value = getDataFormatter().formatCellValue(cell); } } } else if (cellType == CellType.BOOLEAN) { value = cell.getBooleanCellValue() ? "true" : "false"; } } else { throw e; } } } else if (cellType == CellType.STRING) { if (returnURLInsteadOfName) { Hyperlink link = cell.getHyperlink(); if (link != null) { if (concatenateLabelUrl) { String url = link.getAddress(); if (url == null) { url = ""; } String label = link.getLabel(); if (label == null) { label = ""; } value = label + "|" + url; } else { value = link.getAddress(); } } else { value = cell.getStringCellValue(); } } else { value = cell.getStringCellValue(); } } else if (cellType == CellType.NUMERIC) { if (DateUtil.isCellDateFormatted(cell)) { value = getDataFormatter().formatCellValue(cell); } else { if (overrideExcelNumberFormat) { value = getNumberFormat(originalColumnIndex).format(cell.getNumericCellValue()); } else { value = getDataFormatter().formatCellValue(cell); } } } else if (cellType == CellType.BOOLEAN) { value = cell.getBooleanCellValue() ? "true" : "false"; } else if (cellType == CellType.BLANK) { value = null; } } return value; }
From source file:de.jlo.talendcomp.excel.SpreadsheetInput.java
License:Apache License
public boolean isCellValueEmpty(Cell cell) { if (cell == null) { return true; } else {/*from ww w . ja v a 2s. co m*/ CellType cellType = cell.getCellTypeEnum(); if (cellType == CellType.BLANK) { return true; } else if (cellType == CellType.FORMULA) { try { String s = getDataFormatter().formatCellValue(cell, getFormulaEvaluator()); if (s == null || s.trim().isEmpty()) { return true; } else { return false; } } catch (Exception e) { return true; } } else if (cellType == CellType.STRING) { String s = cell.getStringCellValue(); if (s == null || s.trim().isEmpty()) { return true; } else { return false; } } else { return false; } } }
From source file:de.jlo.talendcomp.excel.SpreadsheetNamedCellInput.java
License:Apache License
public Object getCellValue() { if (currentNamedCell != null) { // cell.getCellTypeEnum() == CellType.BLANK if (currentNamedCell.getCellTypeEnum() == CellType.BLANK) { valueClass = null;//from w ww . j a v a 2 s . com return null; } else if (currentNamedCell.getCellTypeEnum() == CellType.BOOLEAN) { valueClass = "java.lang.Boolean"; return currentNamedCell.getBooleanCellValue(); } else if (currentNamedCell.getCellTypeEnum() == CellType.ERROR) { valueClass = null; return null; } else if (currentNamedCell.getCellTypeEnum() == CellType.FORMULA) { valueClass = "java.lang.String"; return getDataFormatter().formatCellValue(currentNamedCell, getFormulaEvaluator()); } else if (currentNamedCell.getCellTypeEnum() == CellType.NUMERIC) { if (DateUtil.isCellDateFormatted(currentNamedCell)) { valueClass = "java.util.Date"; return currentNamedCell.getDateCellValue(); } else { valueClass = "java.lang.Double"; return currentNamedCell.getNumericCellValue(); } } else if (currentNamedCell.getCellTypeEnum() == CellType.STRING) { valueClass = "java.lang.String"; return currentNamedCell.getStringCellValue(); } else { valueClass = null; return null; } } else { valueClass = null; return null; } }
From source file:de.jlo.talendcomp.excel.SpreadsheetOutput.java
License:Apache License
private void setCellHyperLink(Cell cell, String url) { if (url.contains("://")) { Hyperlink link = creationHelper.createHyperlink(HyperlinkType.URL); link.setAddress(url);/*from www.j a v a 2 s . c o m*/ cell.setHyperlink(link); } else if (url.startsWith("mailto:")) { Hyperlink link = creationHelper.createHyperlink(HyperlinkType.EMAIL); link.setAddress(url); cell.setHyperlink(link); } else { Hyperlink link = creationHelper.createHyperlink(HyperlinkType.FILE); link.setAddress(url); cell.setHyperlink(link); } if (cell.getCellTypeEnum() == CellType.BLANK) { cell.setCellValue(url); } }