org.apache.poi.xssf.usermodel.XSSFRelation Java Examples

The following examples show how to use org.apache.poi.xssf.usermodel.XSSFRelation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReadOnlySharedStringsTable.java    From myexcel with Apache License 2.0 5 votes vote down vote up
/**
 * @param pkg          The {@link OPCPackage} to use as basis for the shared-strings table.
 * @param stringsCache stringsCache
 * @throws IOException  If reading the data from the package fails.
 * @throws SAXException if parsing the XML data fails.
 * @since POI 3.14-Beta3
 */
public ReadOnlySharedStringsTable(OPCPackage pkg, StringsCache stringsCache)
        throws IOException, SAXException {
    this.stringsCache = stringsCache;
    ArrayList<PackagePart> parts =
            pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());

    // Some workbooks have no shared strings table.
    if (parts.size() > 0) {
        PackagePart sstPart = parts.get(0);
        readFrom(sstPart.getInputStream());
    }
}
 
Example #2
Source File: XlsxSaxAnalyser.java    From easyexcel with Apache License 2.0 4 votes vote down vote up
public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStream) throws Exception {
    this.xlsxReadContext = xlsxReadContext;
    // Initialize cache
    XlsxReadWorkbookHolder xlsxReadWorkbookHolder = xlsxReadContext.xlsxReadWorkbookHolder();

    OPCPackage pkg = readOpcPackage(xlsxReadWorkbookHolder, decryptedStream);
    xlsxReadWorkbookHolder.setOpcPackage(pkg);

    ArrayList<PackagePart> packageParts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());

    if (!CollectionUtils.isEmpty(packageParts)) {
        PackagePart sharedStringsTablePackagePart = packageParts.get(0);

        // Specify default cache
        defaultReadCache(xlsxReadWorkbookHolder, sharedStringsTablePackagePart);

        // Analysis sharedStringsTable.xml
        analysisSharedStringsTable(sharedStringsTablePackagePart.getInputStream(), xlsxReadWorkbookHolder);
    }

    XSSFReader xssfReader = new XSSFReader(pkg);
    analysisUse1904WindowDate(xssfReader, xlsxReadWorkbookHolder);

    xlsxReadWorkbookHolder.setStylesTable(xssfReader.getStylesTable());
    sheetList = new ArrayList<ReadSheet>();
    sheetMap = new HashMap<Integer, InputStream>();
    commentsTableMap = new HashMap<Integer, CommentsTable>();
    XSSFReader.SheetIterator ite = (XSSFReader.SheetIterator)xssfReader.getSheetsData();
    int index = 0;
    if (!ite.hasNext()) {
        throw new ExcelAnalysisException("Can not find any sheet!");
    }
    while (ite.hasNext()) {
        InputStream inputStream = ite.next();
        sheetList.add(new ReadSheet(index, ite.getSheetName()));
        sheetMap.put(index, inputStream);
        if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) {
            CommentsTable commentsTable = ite.getSheetComments();
            if (null != commentsTable) {
                commentsTableMap.put(index, commentsTable);
            }
        }
        index++;
    }
}
 
Example #3
Source File: BufferedStringsTable.java    From excel-streaming-reader with Apache License 2.0 4 votes vote down vote up
public static BufferedStringsTable getSharedStringsTable(File tmp, int cacheSize, OPCPackage pkg)
    throws IOException {
  List<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());
  return parts.size() == 0 ? null : new BufferedStringsTable(parts.get(0), tmp, cacheSize);
}