android poi demo,android – 使用Apache POI打开.xlsx文件时发生...

我一直在研究一个Android应用程序,我必须打开.xls和.xlsx文件才能进一步实现.在.xls的情况下一切正常,但是当我尝试打开.xls x文件时,它给了我异常.下面是我的代码

请帮我解决这些异常

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RESULT_code && resultCode == RESULT_OK && null != data) {

String FileName = data.getData().getLastPathSegment();

String FilePath = data.getData().getPath();

if(FilePath.endsWith(".xlsx")){

try{

FileInputStream file = new FileInputStream(new File(FilePath));

XSSFWorkbook myWorkBook2 = new XSSFWorkbook(file);

XSSFSheet mySheet2 = myWorkBook2.getSheetAt(0);}

catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

我使用的罐子:

> dom4j-1.6.1.jar

> log4j-1.2.13.jar

> poi-3.9-20121203.jar

> poi-ooxml-3.9-20121203.jar

> xmlbeans-2.3.0.jar

Logcat错误

07-05 14:09:31.654: E/AndroidRuntime(6774): FATAL EXCEPTION: main

07-05 14:09:31.654: E/AndroidRuntime(6774): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=android.intent.action.GET_CONTENT cat=[android.intent.category.OPENABLE] dat=file:///sdcard/test .xlsx flg=0x3000000 cmp=miyowa.android.microsoft.wlm/com.miyowa.android.framework.ui.miyowaExplorer.MiyowaExplorer (has extras) }} to activity {com.example.converter/com.example.converter.Homepage}: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException

07-05 14:09:31.654: E/AndroidRuntime(6774): at android.app.ActivityThread.deliverResults(ActivityThread.java:3142)

07-05 14:09:31.654: E/AndroidRuntime(6774): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3185)

07-05 14:09:31.654: E/AndroidRuntime(6774): at android.app.ActivityThread.access$1100(ActivityThread.java:134)

07-05 14:09:31.654: E/AndroidRuntime(6774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)

07-05 14:09:31.654: E/AndroidRuntime(6774): at android.os.Handler.dispatchMessage(Handler.java:99)

07-05 14:09:31.654: E/AndroidRuntime(6774): at android.os.Looper.loop(Looper.java:137)

07-05 14:09:31.654: E/AndroidRuntime(6774): at android.app.ActivityThread.main(ActivityThread.java:4666)

07-05 14:09:31.654: E/AndroidRuntime(6774): at java.lang.reflect.Method.invokeNative(Native Method)

07-05 14:09:31.654: E/AndroidRuntime(6774): at java.lang.reflect.Method.invoke(Method.java:511)

07-05 14:09:31.654: E/AndroidRuntime(6774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)

07-05 14:09:31.654: E/AndroidRuntime(6774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)

07-05 14:09:31.654: E/AndroidRuntime(6774): at dalvik.system.NativeStart.main(Native Method)

07-05 14:09:31.654: E/AndroidRuntime(6774): Caused by: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException

07-05 14:09:31.654: E/AndroidRuntime(6774): at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)

07-05 14:09:31.654: E/AndroidRuntime(6774): at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)

07-05 14:09:31.654: E/AndroidRuntime(6774): at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)

07-05 14:09:31.654: E/AndroidRuntime(6774): at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:207)

07-05 14:09:31.654: E/AndroidRuntime(6774): at com.example.converter.Homepage.onActivityResult(Homepage.java:358)

07-05 14:09:31.654: E/AndroidRuntime(6774): at android.app.Activity.dispatchActivityResult(Activity.java:4694)

07-05 14:09:31.654: E/AndroidRuntime(6774): at android.app.ActivityThread.deliverResults(ActivityThread.java:3138)

07-05 14:09:31.654: E/AndroidRuntime(6774): ... 11 more

07-05 14:09:31.654: E/AndroidRuntime(6774): Caused by: java.lang.reflect.InvocationTargetException

07-05 14:09:31.654: E/AndroidRuntime(6774): at java.lang.reflect.Constructor.constructNative(Native Method)

07-05 14:09:31.654: E/AndroidRuntime(6774): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)

07-05 14:09:31.654: E/AndroidRuntime(6774): at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)

07-05 14:09:31.654: E/AndroidRuntime(6774): ... 17 more

07-05 14:09:31.654: E/AndroidRuntime(6774): Caused by: java.lang.NoClassDefFoundError: org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory

07-05 14:09:31.654: E/AndroidRuntime(6774): at org.apache.poi.xssf.model.ThemesTable.(ThemesTable.java:44)

07-05 14:09:31.654: E/AndroidRuntime(6774): ... 20 more

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值