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