Android Apache XLSX导入问题

时间:2018-03-08 10:01:08

标签: android apache-poi uri

我正在尝试使用以下代码将excel文件导入android:

Workbook workbook = null;


    try {
        workbook = WorkbookFactory.create(getContentResolver().openInputStream(uriExcelFile));
        int sheets = 0 ;
        if(workbook!=null){
            sheets = workbook.getNumberOfSheets();
        }


        /* Read the first worksheet from the excel file */
        Sheet firstSheet = workbook.getSheetAt(0);

该代码适用于.xls文件,但是当我尝试导入.xlsx文件时,应用程序崩溃时出现以下堆栈跟踪:

FATAL EXCEPTION: IntentService[SimpleIntentService]
Process: in.hulum.intentservice, PID: 26221
javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
                                                                        at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
                                                                        at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
                                                                        at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
                                                                        at javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)
                                                                        at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
                                                                        at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161)
                                                                        at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
                                                                        at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:97)
                                                                        at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324)
                                                                        at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:184)
                                                                        at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:149)
                                                                        at in.hulum.intentservice.SimpleIntentService.handleActionImportRawData(SimpleIntentService.java:163)
                                                                        at in.hulum.intentservice.SimpleIntentService.onHandleIntent(SimpleIntentService.java:116)
                                                                        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:68)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:154)
                                                                        at android.os.HandlerThread.run(HandlerThread.java:61)

我该如何解决?

0 个答案:

没有答案