Search in sources :

Example 1 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage 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 OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project goci by EBISPOT.

the class SheetCreationService method createSheet.

public XSSFSheet createSheet(String fileName) throws InvalidFormatException, IOException, InvalidOperationException {
    // Open file
    OPCPackage pkg = OPCPackage.open(fileName);
    XSSFWorkbook current = new XSSFWorkbook(pkg);
    pkg.close();
    return current.getSheetAt(0);
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Example 3 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage 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 4 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class XDGFFileHandler method test.

// a test-case to test this locally without executing the full TestAllFiles
@Test
public void test() throws Exception {
    OPCPackage pkg = OPCPackage.open("test-data/diagram/test.vsdx", PackageAccess.READ);
    try {
        XmlVisioDocument doc = new XmlVisioDocument(pkg);
        new POIXMLDocumentHandler().handlePOIXMLDocument(doc);
    } finally {
        pkg.close();
    }
}
Also used : XmlVisioDocument(org.apache.poi.xdgf.usermodel.XmlVisioDocument) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 5 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class XSSFBFileHandler method handleExtracting.

@Override
public void handleExtracting(File file) throws Exception {
    OPCPackage pkg = OPCPackage.open(file, PackageAccess.READ);
    try {
        testOne(pkg);
    } finally {
        pkg.close();
    }
    pkg = OPCPackage.open(file, PackageAccess.READ);
    try {
        testNotHandledByWorkbookException(pkg);
    } finally {
        pkg.close();
    }
}
Also used : OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Aggregations

OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)116 Test (org.junit.Test)54 InputStream (java.io.InputStream)29 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)25 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)21 File (java.io.File)19 IOException (java.io.IOException)17 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)13 SignatureConfig (org.apache.poi.poifs.crypt.dsig.SignatureConfig)10 SignatureInfo (org.apache.poi.poifs.crypt.dsig.SignatureInfo)10 XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)10 OutputStream (java.io.OutputStream)9 ArrayList (java.util.ArrayList)9 FileOutputStream (java.io.FileOutputStream)8 InvalidOperationException (org.apache.poi.openxml4j.exceptions.InvalidOperationException)8 XmlException (org.apache.xmlbeans.XmlException)8 FileInputStream (java.io.FileInputStream)7