private void endCellValue(String name) throws SAXException { // ensure size if (curCol >= curRowContent.length) { curRowContent = Arrays.copyOf(curRowContent, (int)(curCol * 1.5)); } if (CELL_VALUE_TAG.equals(name)) { switch (currentCellType) { case STRING: int idx = Integer.parseInt(currentCellValue); currentCellValue = new XSSFRichTextString(sst.getEntryAt(idx)).toString(); currentCellType = FieldType.EMPTY; break; } curRowContent[curCol] = currentCellValue; } else if (CELL_VALUE_TAG_1.equals(name)) { curRowContent[curCol] = currentCellValue; } }
if ( event == XMLStreamConstants.START_ELEMENT && sheetReader.getLocalName().equals( "v" ) ) { int idx = Integer.parseInt( sheetReader.getElementText() ); String content = new XSSFRichTextString( sst.getEntryAt( idx ) ).toString(); headerRow.add( content ); break; event = sheetReader.next(); if ( event == XMLStreamConstants.CHARACTERS ) { String content = new XSSFRichTextString( sheetReader.getText() ).toString(); headerRow.add( content ); break;
thisStr = rtsi.toString(); break;
break; case INLINESTR: result = new XSSFRichTextString(value.toString()).toString(); break; case SSTINDEX:
break; case INLINESTR: result = new XSSFRichTextString(value.toString()).toString(); break; case SSTINDEX:
return getRichStringCellValue().toString(); case FORMULA: return getCellFormula();
/** * 根据数据类型获取数据 * * @param value * @return */ private String getCellValue(String value) { switch (cellFormatStr) { case INLINESTR: return new XSSFRichTextString(value).toString(); default: return String.valueOf(value); } }
private String getCellValue(String value) { switch (mNextCellType) { case BOOL: return value.charAt(0) == '0' ? "FALSE" : "TRUE"; case ERROR: return "\"ERROR:" + value + '"'; case FORMULA: return '"' + value + '"'; case INLINESTR: return new XSSFRichTextString(value).toString(); case STRING: return String.valueOf(value); } return value; }
/** * Resolve the given value with respect to whether it is a reference to element in shared strings table. * Also decode the final value. * * @param value Value read in element. * @param lookupNextValueInSST Whether the value is an index into the shared strings table. * @return */ private String resolveValue(String value, boolean lookupNextValueInSST) { if(lookupNextValueInSST) { int idx = (int)Double.parseDouble(value); return new XSSFRichTextString(sst.getEntryAt(idx)).toString(); } return new XSSFRichTextString(value).toString(); }
/** * Returns the contents of the cell, with no formatting applied * * @return */ String unformattedContents() { switch(currentCell.getType()) { case "s": //string stored in shared table if (!lastContents.isEmpty()) { int idx = Integer.parseInt(lastContents); return new XSSFRichTextString(sst.getEntryAt(idx)).toString(); } return lastContents; case "inlineStr": //inline string (not in sst) return new XSSFRichTextString(lastContents).toString(); default: return lastContents; } }
/** * Returns the contents of the cell, with no formatting applied * * @return */ String unformattedContents() { switch (currentCell.getType()) { case "s": // string stored in shared table int idx = Integer.parseInt(lastContents); return new XSSFRichTextString(sst.getEntryAt(idx)).toString(); case "inlineStr": // inline string (not in sst) return new XSSFRichTextString(lastContents).toString(); default: return lastContents; } }
/** * Returns the contents of the cell, with no formatting applied * * @return */ String unformattedContents() { switch (currentCell.getType()) { case "s": // string stored in shared table int idx = Integer.parseInt(lastContents); return new XSSFRichTextString(sst.getEntryAt(idx)).toString(); case "inlineStr": // inline string (not in sst) return new XSSFRichTextString(lastContents).toString(); default: return lastContents; } }
/** * 07版本复杂数据 * @param rich * @return */ private String getXSSFRichString(XSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0, lastIndex = 0; for (int i = 1; i <= nums; i++) { sb.append("<span "); try { sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1))); sb.append("_"); sb.append(cssRandom); sb.append("'"); } catch (Exception e) { } sb.append(">"); currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich.getIndexOfFormattingRun(i); sb.append( XmlEscapers.xmlContentEscaper().escape(text.substring(lastIndex, currentIndex))); sb.append("</span>"); lastIndex = currentIndex; } return sb.toString(); }
/** * 07版本复杂数据 * @param rich * @return */ private String getXSSFRichString(XSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0, lastIndex = 0; for (int i = 1; i <= nums; i++) { sb.append("<span "); try { sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1))); sb.append("_"); sb.append(cssRandom); sb.append("'"); } catch (Exception e) { } sb.append(">"); currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich.getIndexOfFormattingRun(i); sb.append( XmlEscapers.xmlContentEscaper().escape(text.substring(lastIndex, currentIndex))); sb.append("</span>"); lastIndex = currentIndex; } return sb.toString(); }
/** * 07版本复杂数据 * * @param rich * @return */ private String getXSSFRichString(XSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0, lastIndex = 0; for (int i = 1; i <= nums; i++) { sb.append("<span "); try { sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1))); sb.append("_"); sb.append(cssRandom); sb.append("'"); } catch (Exception e) { } sb.append(">"); currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich.getIndexOfFormattingRun(i); sb.append(XmlEscapers.xmlContentEscaper().escape(text.substring(lastIndex, currentIndex))); sb.append("</span>"); lastIndex = currentIndex; } return sb.toString(); }
/** * 07版本复杂数据 * @param rich * @return */ private String getXSSFRichString(XSSFRichTextString rich) { int nums = rich.numFormattingRuns(); StringBuilder sb = new StringBuilder(); String text = rich.toString(); int currentIndex = 0, lastIndex = 0; for (int i = 1; i <= nums; i++) { sb.append("<span "); try { sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1))); sb.append("_"); sb.append(cssRandom); sb.append("'"); } catch (Exception e) { } sb.append(">"); currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich .getIndexOfFormattingRun(i); sb.append(XmlEscapers.xmlContentEscaper().escape( text.substring(lastIndex, currentIndex))); sb.append("</span>"); lastIndex = currentIndex; } return sb.toString(); }
@Override public void endElement(String uri, String localName, String name) throws SAXException { // Process the last contents as required. // Do now, as characters() may be called more than once if(nextIsString) { Integer idx = Integer.valueOf(lastContents); lastContents = lruCache.get(idx); if (lastContents == null && !lruCache.containsKey(idx)) { lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString(); lruCache.put(idx, lastContents); } nextIsString = false; } // v => contents of a cell // Output after we've seen the string contents if(name.equals("v") || (inlineStr && name.equals("c"))) { System.out.println(lastContents); } }
/** * Tries to format the contents of the last contents appropriately based on the type of cell and the discovered * numeric format. * * @return */ String formattedContents() { switch (currentCell.getType()) { case "s": // string stored in shared table int idx = Integer.parseInt(lastContents); return new XSSFRichTextString(sst.getEntryAt(idx)).toString(); case "inlineStr": // inline string (not in sst) return new XSSFRichTextString(lastContents).toString(); case "str": // return lastContents; case "e": // error type return StringUtils.EMPTY;// "ERROR: " + lastContents; case "n": // numeric type if (currentCell.getNumericFormat() != null && lastContents.length() > 0) { return dataFormatter.formatRawCellContents(Double.parseDouble(lastContents), currentCell.getNumericFormatIndex(), currentCell.getNumericFormat()); } else { return lastContents; } default: return lastContents; } }
/** * Tries to format the contents of the last contents appropriately based on the type of cell and the discovered * numeric format. * * @return */ String formattedContents() { switch (currentCell.getType()) { case "s": // string stored in shared table int idx = Integer.parseInt(lastContents); return new XSSFRichTextString(sst.getEntryAt(idx)).toString(); case "inlineStr": // inline string (not in sst) return new XSSFRichTextString(lastContents).toString(); case "str": // return lastContents; case "e": // error type return StringUtils.EMPTY;// "ERROR: " + lastContents; case "n": // numeric type if (currentCell.getNumericFormat() != null && lastContents.length() > 0) { return dataFormatter.formatRawCellContents(Double.parseDouble(lastContents), currentCell.getNumericFormatIndex(), currentCell.getNumericFormat()); } else { return lastContents; } default: return lastContents; } }