【问题标题】:How to display .docx file contents in a textview on Android Activity?如何在 Android Activity 的文本视图中显示 .docx 文件内容?
【发布时间】:2015-02-28 05:36:05
【问题描述】:

我正在尝试使用代码在 Android Activity 的 textview 中显示 .doc/.docx 文件的内容。

File sdcard = Environment.getExternalStorageDirectory();

    File file = new File(sdcard,"demo.docx");

    StringBuilder text = new StringBuilder();

    try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;

        while ((line = br.readLine()) != null) {
            text.append(line);
            text.append('\n');
        }
        br.close();
    }
    catch (IOException e) {
    }
    output.setText(text);

但是,我得到这样的输出,

http://i.stack.imgur.com/TAqCW.jpg

它适用于 .txt 文件,但不适用于 .doc/.docx 文件。 请帮助我,如何在android活动的textview中显示.doc/.docx文件的内容?

【问题讨论】:

  • 第 1 步:找到一个能够解析 .doc 和 .docx 文件的库。它们不是简单的文本文件。
  • 感谢您的回复,我是 android 新手,所以当您找到该库时请告知我,该库是否可以离线使用。
  • 感谢您的回复 Daniel Nugent,如果您单击该站点中提到的 OliveDocLibrary 的链接,则会显示 404 错误。 :-( 我已经检查过了 :-(

标签: java android android-xml


【解决方案1】:

Open Microsoft Word docx file with Java

查看该问题以获取解析文本的一般解决方案。

我遇到了同样的问题,但我想将文本传递到 java textArea 而不是 android textView。对于特定于 Android 的解决方案,请查看

https://github.com/plutext/AndroidDocxToHtml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-06
    • 2012-07-26
    • 2019-03-13
    • 2013-06-17
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 2013-03-20
    相关资源
    最近更新 更多