List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle getDataFormat
@Override public short getDataFormat()
From source file:org.talend.dataprep.schema.xls.streaming.StreamingSheetReader.java
License:Open Source License
/** * Read the numeric format string out of the styles table for this cell. Stores the result in the Cell. * * @param startElement/*from ww w. j a va 2 s .co m*/ * @param cell */ void setFormatString(StartElement startElement, StreamingCell cell) { Attribute cellStyle = startElement.getAttributeByName(new QName("s")); String cellStyleString = (cellStyle != null) ? cellStyle.getValue() : null; XSSFCellStyle style = null; if (cellStyleString != null) { style = stylesTable.getStyleAt(Integer.parseInt(cellStyleString)); } else if (stylesTable.getNumCellStyles() > 0) { style = stylesTable.getStyleAt(0); } if (style != null) { cell.setNumericFormatIndex(style.getDataFormat()); String formatString = style.getDataFormatString(); if (formatString != null) { cell.setNumericFormat(formatString); } else { cell.setNumericFormat(BuiltinFormats.getBuiltinFormat(cell.getNumericFormatIndex())); } } else { cell.setNumericFormatIndex(null); cell.setNumericFormat(null); } }
From source file:service.XSSFSheetHandler.java
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { if ("inlineStr".equals(name) || "v".equals(name)) { vIsOpen = true;/*from w w w .j a v a2 s . com*/ // Clear contents cache value.setLength(0); } // c => cell else if ("c".equals(name)) { // Get the cell reference String r = attributes.getValue("r"); int firstDigit = -1; for (int c = 0; c < r.length(); ++c) { if (Character.isDigit(r.charAt(c))) { firstDigit = c; break; } } thisColumn = nameToColumn(r.substring(0, firstDigit)); // Set up defaults. this.nextDataType = ReadExcelFile.xssfDataType.NUMBER; this.formatIndex = -1; this.formatString = null; String cellType = attributes.getValue("t"); String cellStyleStr = attributes.getValue("s"); if ("b".equals(cellType)) nextDataType = ReadExcelFile.xssfDataType.BOOL; else if ("e".equals(cellType)) nextDataType = ReadExcelFile.xssfDataType.ERROR; else if ("inlineStr".equals(cellType)) nextDataType = ReadExcelFile.xssfDataType.INLINESTR; else if ("s".equals(cellType)) nextDataType = ReadExcelFile.xssfDataType.SSTINDEX; else if ("str".equals(cellType)) nextDataType = ReadExcelFile.xssfDataType.FORMULA; else if (cellStyleStr != null) { // It's a number, but almost certainly one // with a special style or format int styleIndex = Integer.parseInt(cellStyleStr); XSSFCellStyle style = stylesTable.getStyleAt(styleIndex); this.formatIndex = style.getDataFormat(); this.formatString = style.getDataFormatString(); if (this.formatString == null) this.formatString = BuiltinFormats.getBuiltinFormat(this.formatIndex); } } }