无法使用Android应用程序打开word文件

时间:2014-11-06 14:53:12

标签: android ms-word

我已在我的app中保存了扩展名为.docx的文件。该文件保存在SD卡中。该文件在我的SD卡中显示为word文件,但我无法打开它(使用polaris或任何其他默认软件)和消息"不支持的文件"出现。

当我用.txt扩展名保存文件时,我可以打开它。

    public void Savedoc(View v)
    {
        String filename = "file" + sn + ".docx";
         String filepath = "MyFileStorage";

         myExternalFile = new File(getExternalFilesDir(filepath), filename);


         try {
                FileOutputStream fos = new FileOutputStream(myExternalFile);
                fos.write(ly.getBytes());
                fos.close();
               } catch (IOException e) {
                e.printStackTrace();
               }


    }

谢谢你alexandru ...但现在我收到一条关于运行应用程序的错误消息说明"此元素的Javadoc既不能在附加源中找到,也不能在附加的Javadoc" .pls帮助中找到。

1 个答案:

答案 0 :(得分:0)

您需要使用Apache POI才能正确创建.docx文件。

我发现了this answer的代码段:

XWPFDocument document = new XWPFDocument();
XWPFParagraph tmpParagraph = document.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("LALALALAALALAAAA");
tmpRun.setFontSize(18);
document.write(new FileOutputStream(new File("yourpathhere")));

您可以找到有关how to use XWPF here的更多信息。

相关问题