List of usage examples for org.apache.poi.util POILogger ERROR
int ERROR
To view the source code for org.apache.poi.util POILogger ERROR.
Click Source Link
From source file:com.adanac.excel.reader.hssf.ExcelFormatTrackingHSSFListener.java
License:Apache License
/** * Returns the format string, eg $##.##, for the given number format index. *///w w w . j av a2s . c o m public String getFormatString(int formatIndex) { String format = null; if (formatIndex >= ExcelHSSFDataFormat.getNumberOfBuiltinBuiltinFormats()) { FormatRecord tfr = _customFormatRecords.get(Integer.valueOf(formatIndex)); if (tfr == null) { logger.log(POILogger.ERROR, "Requested format at index " + formatIndex + ", but it wasn't found"); } else { format = tfr.getFormatString(); } } else { format = ExcelHSSFDataFormat.getBuiltinFormat((short) formatIndex); } return format; }
From source file:com.adanac.excel.reader.hssf.ExcelFormatTrackingHSSFListener.java
License:Apache License
/** * Returns the index of the format string, used by your cell, or -1 if none * found/* w ww . j a v a 2 s . co m*/ */ public int getFormatIndex(CellValueRecordInterface cell) { ExtendedFormatRecord xfr = _xfRecords.get(cell.getXFIndex()); if (xfr == null) { logger.log(POILogger.ERROR, "Cell " + cell.getRow() + "," + cell.getColumn() + " uses XF with index " + cell.getXFIndex() + ", but we don't have that"); return -1; } return xfr.getFormatIndex(); }
From source file:com.adanac.excel.reader.sax.ExcelXSSFSheetXMLHandler.java
License:Apache License
@Override public void endElement(String uri, String localName, String name) throws SAXException { String thisStr = null;/*from ww w .ja v a 2 s. com*/ // v => contents of a cell if (isTextTag(name)) { vIsOpen = false; // Process the value contents as required, now we have it all switch (nextDataType) { case BOOLEAN: char first = value.charAt(0); thisStr = first == '0' ? "FALSE" : "TRUE"; break; case ERROR: thisStr = "ERROR:" + value.toString(); break; case FORMULA: if (formulasNotResults) { thisStr = formula.toString(); } else { String fv = value.toString(); if (this.formatString != null) { try { // Try to use the value as a formattable number double d = Double.parseDouble(fv); thisStr = formatter.formatRawCellContents(d, this.formatIndex, this.formatString); } catch (NumberFormatException e) { // Formula is a String result not a Numeric one thisStr = fv; } } else { // No formating applied, just do raw value in all cases thisStr = fv; } } break; case INLINE_STRING: // TODO: Can these ever have formatting on them? XSSFRichTextString rtsi = new XSSFRichTextString(value.toString()); thisStr = rtsi.toString(); break; case SST_STRING: String sstIndex = value.toString(); try { int idx = Integer.parseInt(sstIndex); XSSFRichTextString rtss = new XSSFRichTextString(sharedStringsTable.getEntryAt(idx)); thisStr = rtss.toString(); } catch (NumberFormatException ex) { logger.log(POILogger.ERROR, "Failed to parse SST index '" + sstIndex, ex); } break; case NUMBER: String n = value.toString(); if (this.formatString != null && n.length() > 0) thisStr = formatter.formatRawCellContents(Double.parseDouble(n), this.formatIndex, this.formatString); else thisStr = n; break; default: thisStr = "(TODO: Unexpected type: " + nextDataType + ")"; break; } // Do we have a comment for this cell? //checkForEmptyCellComments(EmptyCellCommentsCheckType.CELL); XSSFComment comment = commentsTable != null ? commentsTable.findCellComment(cellRef) : null; // Output ?? output.cell(rowNum, cellRef, thisStr, comment); } else if ("f".equals(name)) { fIsOpen = false; } else if ("is".equals(name)) { isIsOpen = false; } else if ("row".equals(name)) { // Handle any "missing" cells which had comments attached checkForEmptyCellComments(EmptyCellCommentsCheckType.END_OF_ROW); // Finish up the row output.endRow(rowNum); // some sheets do not have rowNum set in the XML, Excel can read // them so we should try to read them as well nextRowNum = rowNum + 1; } else if ("sheetData".equals(name)) { // Handle any "missing" cells which had comments attached checkForEmptyCellComments(EmptyCellCommentsCheckType.END_OF_SHEET_DATA); } else if ("oddHeader".equals(name) || "evenHeader".equals(name) || "firstHeader".equals(name)) { hfIsOpen = false; output.headerFooter(headerFooter.toString(), true, name); } else if ("oddFooter".equals(name) || "evenFooter".equals(name) || "firstFooter".equals(name)) { hfIsOpen = false; output.headerFooter(headerFooter.toString(), false, name); } }
From source file:utilities.SmapSheetXMLHandler.java
License:Apache License
@Override public void endElement(String uri, String localName, String qName) throws SAXException { if (uri != null && !uri.equals(NS_SPREADSHEETML)) { return;//from w ww .j av a 2s. co m } String thisStr = null; // v => contents of a cell if (isTextTag(localName)) { vIsOpen = false; // Process the value contents as required, now we have it all switch (nextDataType) { case BOOLEAN: char first = value.charAt(0); thisStr = first == '0' ? "FALSE" : "TRUE"; break; case ERROR: thisStr = "ERROR:" + value; break; case FORMULA: if (formulasNotResults) { thisStr = formula.toString(); } else { String fv = value.toString(); if (this.formatString != null) { try { // Try to use the value as a formattable number double d = Double.parseDouble(fv); thisStr = formatter.formatRawCellContents(d, this.formatIndex, this.formatString); } catch (NumberFormatException e) { // Formula is a String result not a Numeric one thisStr = fv; } } else { // No formatting applied, just do raw value in all cases thisStr = fv; } } break; case INLINE_STRING: // TODO: Can these ever have formatting on them? XSSFRichTextString rtsi = new XSSFRichTextString(value.toString()); thisStr = rtsi.toString(); break; case SST_STRING: String sstIndex = value.toString(); try { int idx = Integer.parseInt(sstIndex); RichTextString rtss = sharedStringsTable.getItemAt(idx); thisStr = rtss.toString(); } catch (NumberFormatException ex) { logger.log(POILogger.ERROR, "Failed to parse SST index '" + sstIndex, ex); } break; case NUMBER: String n = value.toString(); if (this.formatString != null && n.length() > 0) { // smap Check for date boolean isDate = false; double d = Double.parseDouble(n); if (DateUtil.isValidExcelDate(d)) { ExcelNumberFormat nf = ExcelNumberFormat.from(style); if (nf != null) { isDate = DateUtil.isADateFormat(nf); } } if (isDate) { try { Date dv = DateUtil.getJavaDate(d); thisStr = sdf.format(dv); } catch (Exception e) { } } else { thisStr = formatter.formatRawCellContents(Double.parseDouble(n), this.formatIndex, this.formatString); } } else thisStr = n; break; default: thisStr = "(TODO: Unexpected type: " + nextDataType + ")"; break; } // Do we have a comment for this cell? checkForEmptyCellComments(EmptyCellCommentsCheckType.CELL); XSSFComment comment = comments != null ? comments.findCellComment(new CellAddress(cellRef)) : null; // Output output.cell(cellRef, thisStr, comment, nextDataType, formatString); } else if ("f".equals(localName)) { fIsOpen = false; } else if ("is".equals(localName)) { isIsOpen = false; } else if ("row".equals(localName)) { // Handle any "missing" cells which had comments attached checkForEmptyCellComments(EmptyCellCommentsCheckType.END_OF_ROW); // Finish up the row output.endRow(rowNum); // some sheets do not have rowNum set in the XML, Excel can read them so we should try to read them as well nextRowNum = rowNum + 1; } else if ("sheetData".equals(localName)) { // Handle any "missing" cells which had comments attached checkForEmptyCellComments(EmptyCellCommentsCheckType.END_OF_SHEET_DATA); // indicate that this sheet is now done output.endSheet(); } else if ("oddHeader".equals(localName) || "evenHeader".equals(localName) || "firstHeader".equals(localName)) { hfIsOpen = false; output.headerFooter(headerFooter.toString(), true, localName); } else if ("oddFooter".equals(localName) || "evenFooter".equals(localName) || "firstFooter".equals(localName)) { hfIsOpen = false; output.headerFooter(headerFooter.toString(), false, localName); } }