在Android中解析doc,docx,xls,xlsx,pptx等格式文件
2012-05-18 13:41
756 查看
导读:有的时候我们在开发android中需要解析一些我们比较常用的格式,比如doc、docx、xls、xlsx,那么我们要是正常的话就解析不了。这时我们就要用tm-extractors-0.4.jar。
可以直接复制实验,
解析doc,要tm-extractors-0.4.jar这个包
解析xls,要jxl.jar这个包
头部代码 :
解析doc :
View Code
原文: http://www.eoeandroid.com/qa/2011/1227/504.html
可以直接复制实验,
解析doc,要tm-extractors-0.4.jar这个包
解析xls,要jxl.jar这个包
头部代码 :
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipFile; import jxl.Cell; import jxl.CellType; import jxl.DateCell; import jxl.NumberCell; import jxl.Sheet; import jxl.Workbook; import org.apache.http.util.EncodingUtils; import org.textmining.text.extraction.WordExtractor; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.os.Environment; import android.util.Xml;
解析doc :
View Code
public static String readPPTX(String path) { List<String> ls = new ArrayList<String>(); String river = ""; ZipFile xlsxFile = null; try { xlsxFile = new ZipFile(new File(path));// pptx按照读取zip格式读取 } catch (ZipException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } try { ZipEntry sharedStringXML = xlsxFile.getEntry("[Content_Types].xml");// 找到里面存放内容的文件 InputStream inputStream = xlsxFile.getInputStream(sharedStringXML);// 将得到文件流 XmlPullParser xmlParser = Xml.newPullParser();// 实例化pull xmlParser.setInput(inputStream, "utf-8");// 将流放进pull中 int evtType = xmlParser.getEventType();// 得到标签类型的状态 while (evtType != XmlPullParser.END_DOCUMENT) {// 循环读取流 switch (evtType) { case XmlPullParser.START_TAG: // 判断标签开始读取 String tag = xmlParser.getName();// 得到标签 if (tag.equalsIgnoreCase("Override")) { String s = xmlParser .getAttributeValue(null, "PartName"); if (s.lastIndexOf("/ppt/slides/slide") == 0) { ls.add(s); } } break; case XmlPullParser.END_TAG:// 标签读取结束 break; default: break; } evtType = xmlParser.next();// 读取下一个标签 } } catch (ZipException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } for (int i = 1; i < (ls.size() + 1); i++) {// 假设有6张幻灯片 river += "第" + i + "张················" + "\n"; try { ZipEntry sharedStringXML = xlsxFile.getEntry("ppt/slides/slide" + i + ".xml");// 找到里面存放内容的文件 InputStream inputStream = xlsxFile .getInputStream(sharedStringXML);// 将得到文件流 XmlPullParser xmlParser = Xml.newPullParser();// 实例化pull xmlParser.setInput(inputStream, "utf-8");// 将流放进pull中 int evtType = xmlParser.getEventType();// 得到标签类型的状态 while (evtType != XmlPullParser.END_DOCUMENT) {// 循环读取流 switch (evtType) { case XmlPullParser.START_TAG: // 判断标签开始读取 String tag = xmlParser.getName();// 得到标签 if (tag.equalsIgnoreCase("t")) { river += xmlParser.nextText() + "\n"; } break; case XmlPullParser.END_TAG:// 标签读取结束 break; default: break; } evtType = xmlParser.next();// 读取下一个标签 } } catch (ZipException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } } if (river == null) { river = "解析文件出现问题"; } return river; }
原文: http://www.eoeandroid.com/qa/2011/1227/504.html
相关文章推荐
- 在Android中解析doc,docx,xls,xlsx,pptx等格式文件
- Android打开 解析 doc,docx,xls,xlsx,ppt等格式文件的源码
- 怎样在Android中解析doc、docx、xls、xlsx格式文件?
- 怎样在Android中解析doc、docx、xls、xlsx格式文件
- android中解析doc、docx、xls、xlsx格式文件
- 怎样在Android中解析doc、docx、xls、xlsx格式文件?
- Android中解析doc、docx、xls、xlsx格式文件
- 【Android】Android阅读各种格式文件(包括DOC/DOCX/WPS/XLS/XLSX/PPT/PPTX/TXT/PDF)
- 怎样在Android中解析doc、docx、xls、xlsx格式文件?
- Android中pdf,doc,docx,xls,xlsx,ppt,pptx等office文件预览
- 使用POI将office(doc/docx/ppt/pptx/xls/xlsx)文件转html格式(附带源码)
- android webview 快速实现office文档在线预览展示(doc,docx,xls,xlsx,ppt,pptx)
- "doc", "docx", "xls", "xlsx", "ppt", "pptx",txt。等文件转化为pdf
- android 打开 ppt pptx doc docx xls xlsx pdf office 文档
- android webview 快速实现office文档在线预览展示(doc,docx,xls,xlsx,ppt,pptx)
- office文档在线预览 (doc、docx、ppt、pptx、xls、xlsx)
- 【ASP.NET 进阶】仿百度文库文档在线预览(支持格式.pdf,.doc,docx,xls,xlsx,.ppt,pptx)
- office文档在线预览 (doc、docx、ppt、pptx、xls、xlsx)
- webview 快速实现office文档在线预览展示(doc,docx,xls,xlsx,ppt,pptx)
- POI:支持xls/xlsx文件格式按cell类型解析相关内容(exls 2003/2007 兼容)