Search in sources :

Example 1 with NotOLE2FileException

use of org.apache.poi.poifs.filesystem.NotOLE2FileException in project poi by apache.

the class ExtractorFactory method createExtractor.

public static POITextExtractor createExtractor(File f) throws IOException, OpenXML4JException, XmlException {
    NPOIFSFileSystem fs = null;
    try {
        fs = new NPOIFSFileSystem(f);
        POIOLE2TextExtractor extractor = createExtractor(fs);
        extractor.setFilesystem(fs);
        return extractor;
    } catch (OfficeXmlFileException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        return createExtractor(OPCPackage.open(f.toString(), PackageAccess.READ));
    } catch (NotOLE2FileException ne) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file");
    } catch (OpenXML4JException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    } catch (XmlException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    } catch (IOException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    } catch (RuntimeException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) OfficeXmlFileException(org.apache.poi.poifs.filesystem.OfficeXmlFileException) NotOLE2FileException(org.apache.poi.poifs.filesystem.NotOLE2FileException) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException) POIOLE2TextExtractor(org.apache.poi.POIOLE2TextExtractor)

Example 2 with NotOLE2FileException

use of org.apache.poi.poifs.filesystem.NotOLE2FileException in project jeesuite-libs by vakinge.

the class ExcelPerfModeReader method readAsXLSX.

private List<String> readAsXLSX(String path) {
    OPCPackage opcPackage = null;
    try {
        opcPackage = OPCPackage.open(path, PackageAccess.READ);
        XLSX2CSV xlsx2csv = new XLSX2CSV(opcPackage, System.out, -1);
        return xlsx2csv.process();
    } catch (Exception e) {
        if (e instanceof OLE2NotOfficeXmlFileException || e instanceof NotOLE2FileException || e instanceof NotOfficeXmlFileException || e instanceof OfficeXmlFileException) {
            throw new ExcelOperBaseException("请选择正确格式excel文件");
        }
        if (e instanceof IOException) {
            throw new ExcelOperBaseException("文件读取失败");
        }
        if (e instanceof InvalidOperationException) {
            throw new ExcelOperBaseException(e);
        }
        throw new RuntimeException(e);
    } finally {
        try {
            opcPackage.close();
        } catch (Exception e) {
        }
    }
}
Also used : NotOfficeXmlFileException(org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException) OLE2NotOfficeXmlFileException(org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException) OfficeXmlFileException(org.apache.poi.poifs.filesystem.OfficeXmlFileException) NotOfficeXmlFileException(org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException) OLE2NotOfficeXmlFileException(org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException) NotOLE2FileException(org.apache.poi.poifs.filesystem.NotOLE2FileException) InvalidOperationException(org.apache.poi.openxml4j.exceptions.InvalidOperationException) OLE2NotOfficeXmlFileException(org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException) IOException(java.io.IOException) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) XLSX2CSV(com.jeesuite.common2.excel.convert.XLSX2CSV) OfficeXmlFileException(org.apache.poi.poifs.filesystem.OfficeXmlFileException) NotOLE2FileException(org.apache.poi.poifs.filesystem.NotOLE2FileException) IOException(java.io.IOException) InvalidOperationException(org.apache.poi.openxml4j.exceptions.InvalidOperationException) NotOfficeXmlFileException(org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException) OLE2NotOfficeXmlFileException(org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException)

Aggregations

IOException (java.io.IOException)2 NotOLE2FileException (org.apache.poi.poifs.filesystem.NotOLE2FileException)2 OfficeXmlFileException (org.apache.poi.poifs.filesystem.OfficeXmlFileException)2 XLSX2CSV (com.jeesuite.common2.excel.convert.XLSX2CSV)1 POIOLE2TextExtractor (org.apache.poi.POIOLE2TextExtractor)1 InvalidOperationException (org.apache.poi.openxml4j.exceptions.InvalidOperationException)1 NotOfficeXmlFileException (org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException)1 OLE2NotOfficeXmlFileException (org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException)1 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)1 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)1 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)1 XmlException (org.apache.xmlbeans.XmlException)1