關於在安卓平台上操作doc 等檔案

來源:互聯網
上載者:User

要在安卓上操作 doc、 xls 、 ppt , 還有 docx ... 07 版格式的檔案,另外還有PDF。搜尋了一下,還是有不少的開源項目,胡亂列一下:

兩個比較大的,

1. apache POI

用這個操作了一下,不知道為什麼檔案都打不開。另外,看了看 3.6 的API  確實比較亂,看不太懂,要耐心。

package com.ex.doc;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import org.apache.poi.hwpf.HWPFDocument;import org.apache.poi.hwpf.usermodel.Range;import android.app.Activity;import android.app.AlertDialog;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class Doc extends Activity {private TextView doc_text = null;private Button btn_show = null;private String pathname = "/mnt/sdcard/test.doc";private String content = "content";    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_doc);         File f1 = new File(pathname); // File(pathname);//openFile(f1);content = f1.toString(); //將檔案資訊轉換為可理解的 如路徑HWPFDocument doc = null;try {doc = new HWPFDocument(new FileInputStream(pathname));} catch (FileNotFoundException e) {// TODO 自動產生的 catch 塊e.printStackTrace();} catch (IOException e) {// TODO 自動產生的 catch 塊e.printStackTrace();}Range r = doc.getRange();content = r.text();doc_text = new TextView(this);btn_show = new Button(this);this.btn_show = (Button)super.findViewById(R.id.btn_show); //加 super 加強制轉換this.doc_text = (TextView)super.findViewById(R.id.hello);//this.btn_show.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO 自動產生的方法存根    doc_text.setText("help");//doc_text.setText("hello hello!!!");new AlertDialog.Builder(Doc.this).setTitle("Tips").setMessage(content).show();  }});    }

 

2. iText

好像有人說 iText 寫 word 很方便,但讀的話卻不是很方便, 不知道是不是,看了下 API  的OVEVIEW ,比較清楚,不過內容好多啊,看見就怕。


另外看見一個 CSDN 上的一篇文章 基於Android的Word文檔閱讀器,下來運行了下,也是死掉,可以再研究一下,思路似乎也不錯,DOC
轉 HXML 顯示。



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.