Search in sources :

Example 1 with XSSFReader

use of org.apache.poi.xssf.eventusermodel.XSSFReader in project translationstudio8 by heartsome.

the class Xlsx2TmxHelper method parseXlsxFileAndWriteTmxBody.

public void parseXlsxFileAndWriteTmxBody(String fileName, AbstractWriter tmxWriter, IProgressMonitor monitor) throws ParserConfigurationException, SAXException, IOException, OpenXML4JException {
    this.tmxWriter = tmxWriter;
    this.monitor = monitor;
    File file = new File(fileName);
    long length = file.length();
    monitor.beginTask("", countTotal(length));
    OPCPackage p = OPCPackage.open(fileName, PackageAccess.READ);
    ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(p);
    XSSFReader xssfReader = new XSSFReader(p);
    XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
    try {
        while (iter.hasNext()) {
            InputStream stream = iter.next();
            parse(stream, strings, tmxWriter);
            stream.close();
            // 目前只处理第一个sheet
            break;
        }
    } finally {
        p.close();
    }
    monitor.done();
}
Also used : ReadOnlySharedStringsTable(org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable) InputStream(java.io.InputStream) File(java.io.File) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) XSSFReader(org.apache.poi.xssf.eventusermodel.XSSFReader)

Example 2 with XSSFReader

use of org.apache.poi.xssf.eventusermodel.XSSFReader in project cubrid-manager by CUBRID.

the class XLSXImportFileHandler method getSheets.

/**
	 *
	 * Get the sheets
	 *
	 * @return List<InputStream>
	 * @throws IOException The exception
	 * @throws OpenXML4JException The exception
	 */
public List<InputStream> getSheets() throws IOException, OpenXML4JException {
    // FIXME move this logic to core module
    synchronized (this) {
        if (reader == null) {
            try {
                workbookSteam = new BufferedInputStream(new FileInputStream(fileName));
                OPCPackage pkg = OPCPackage.open(workbookSteam);
                reader = new XSSFReader(pkg);
            } catch (OutOfMemoryError error) {
                throw new RuntimeException(error);
            }
        }
        sharedStringTable = reader.getSharedStringsTable();
        Iterator<InputStream> sheetsIt = reader.getSheetsData();
        List<InputStream> sheets = new ArrayList<InputStream>();
        while (sheetsIt.hasNext()) {
            sheets.add(sheetsIt.next());
        }
        return sheets;
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) FileInputStream(java.io.FileInputStream) XSSFReader(org.apache.poi.xssf.eventusermodel.XSSFReader)

Example 3 with XSSFReader

use of org.apache.poi.xssf.eventusermodel.XSSFReader in project poi by apache.

the class LoadPasswordProtectedXlsxStreaming method printSheetCount.

public static void printSheetCount(final InputStream inputStream) throws Exception {
    AesZipFileZipEntrySource source = AesZipFileZipEntrySource.createZipEntrySource(inputStream);
    try {
        OPCPackage pkg = OPCPackage.open(source);
        try {
            XSSFReader reader = new XSSFReader(pkg);
            SheetIterator iter = (SheetIterator) reader.getSheetsData();
            int count = 0;
            while (iter.hasNext()) {
                iter.next();
                count++;
            }
            System.out.println("sheet count: " + count);
        } finally {
            IOUtils.closeQuietly(pkg);
        }
    } finally {
        IOUtils.closeQuietly(source);
    }
}
Also used : AesZipFileZipEntrySource(org.apache.poi.poifs.crypt.temp.AesZipFileZipEntrySource) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) SheetIterator(org.apache.poi.xssf.eventusermodel.XSSFReader.SheetIterator) XSSFReader(org.apache.poi.xssf.eventusermodel.XSSFReader)

Example 4 with XSSFReader

use of org.apache.poi.xssf.eventusermodel.XSSFReader in project poi by apache.

the class FromHowTo method processAllSheets.

public void processAllSheets(String filename) throws Exception {
    OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ);
    try {
        XSSFReader r = new XSSFReader(pkg);
        SharedStringsTable sst = r.getSharedStringsTable();
        XMLReader parser = fetchSheetParser(sst);
        Iterator<InputStream> sheets = r.getSheetsData();
        while (sheets.hasNext()) {
            System.out.println("Processing new sheet:\n");
            InputStream sheet = sheets.next();
            InputSource sheetSource = new InputSource(sheet);
            parser.parse(sheetSource);
            sheet.close();
            System.out.println("");
        }
    } finally {
        pkg.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) SharedStringsTable(org.apache.poi.xssf.model.SharedStringsTable) InputStream(java.io.InputStream) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) XMLReader(org.xml.sax.XMLReader) XSSFReader(org.apache.poi.xssf.eventusermodel.XSSFReader)

Example 5 with XSSFReader

use of org.apache.poi.xssf.eventusermodel.XSSFReader in project poi by apache.

the class FromHowTo method processFirstSheet.

public void processFirstSheet(String filename) throws Exception {
    OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ);
    try {
        XSSFReader r = new XSSFReader(pkg);
        SharedStringsTable sst = r.getSharedStringsTable();
        XMLReader parser = fetchSheetParser(sst);
        // process the first sheet
        InputStream sheet2 = r.getSheetsData().next();
        InputSource sheetSource = new InputSource(sheet2);
        parser.parse(sheetSource);
        sheet2.close();
    } finally {
        pkg.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) SharedStringsTable(org.apache.poi.xssf.model.SharedStringsTable) InputStream(java.io.InputStream) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) XMLReader(org.xml.sax.XMLReader) XSSFReader(org.apache.poi.xssf.eventusermodel.XSSFReader)

Aggregations

XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)11 InputStream (java.io.InputStream)10 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)9 ReadOnlySharedStringsTable (org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable)5 InputSource (org.xml.sax.InputSource)4 XMLReader (org.xml.sax.XMLReader)4 BufferedInputStream (java.io.BufferedInputStream)3 FileInputStream (java.io.FileInputStream)3 StylesTable (org.apache.poi.xssf.model.StylesTable)3 IOException (java.io.IOException)2 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)2 CommentsTable (org.apache.poi.xssf.model.CommentsTable)2 SharedStringsTable (org.apache.poi.xssf.model.SharedStringsTable)2 SAXException (org.xml.sax.SAXException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1