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

问题描述:

我在应用程序中保存了一个扩展名为.docx的文件,该文件保存在SD卡中。该文件在我的SD卡中显示为一个word文件,但我无法打开它(使用polaris或任何其他默认软件)并显示“不支持的文件”消息。无法使用android应用程序打开word文件

当我用.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(); 
       } 


    } 

谢谢亚历......但现在我得到上运行的应用程序,指出错误消息.PLS帮助“这个元素的Javadoc既不能在所连接的来源,也不附加Javadoc中找到” ...

+0

a .txt实际上就是文本中的文本。 Docx是专有的,并且具有样式。我猜你需要一个特定的库和fileoutputstream来正确地获取文本?当格式刚刚发布时,我曾经遇到过类似的问题,那就是阅读xlsx文件,这很痛苦。祝你好运! – 2014-11-06 15:06:27

您需要使用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

+0

谢谢...但现在我得到一个错误消息运行该应用程序指出“该Javadoc这个元素既不能在附加的源代码中找到,也不是附加的Javadoc”.pls帮助... – user 2014-11-10 09:07:49

+0

谢谢alexandru ...但出现错误“该元素的Javadoc既不能在附加的源代码中找到,也不能附加Javadoc”和应用程序崩溃? – user 2014-11-10 09:15:49

+0

@user你能否给我提供关于错误的更多信息?并请张贴整个堆栈跟踪。 – aluxian 2014-11-10 14:07:43