【问题标题】:Viewing excel files in my android app在我的 android 应用程序中查看 excel 文件
【发布时间】:2011-11-02 11:12:06
【问题描述】:

我正在开发一个 Android 应用程序,我必须在单击按钮时打开和关闭 excel 文件。这些 excel 文件将是只读的。关闭 excel 文件后,它应该将我引导到应用程序。

请给我建议一种方法。

【问题讨论】:

标签: android excel


【解决方案1】:

Android 7.0 更新:

如果您尝试使用外部应用打开应用文档,Android 7.0 将抛出 FileUriExposedException。你需要实现 FileProvider 参考This Answer


这是一条手动路线。

Using JExcelApi in an Android App

How to read excel file using JXL 2.6.12 jar


但这里更容易一些。

open application

但我想你必须找出MIME TYPE

编辑

也获得了 mime 类型

Setting mime type for excel document

更新

所以这样的事情可能会奏效。

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/vnd.ms-excel");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


try {
    startActivity(intent);
} 
catch (ActivityNotFoundException e) {
    Toast.makeText(OpenDoc.this, "No Application Available to View Excel", Toast.LENGTH_SHORT).show();
}

【讨论】:

  • @Samuel Android 7.0 不工作请更新答案
  • @Samuel Android 应用程序,我必须在单击按钮时打开 excel 文件......上面的代码在 marshmellow 6.0 上工作......但在 android 7.1 nougat 中,当我点击时它没有打开,,,请先生帮帮我,,,,
  • 我试过这个代码Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/vnd.ms-excel"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(OpenDoc.this, "No Application Available to View Excel", Toast.LENGTH_SHORT).show(); }
  • @Samuel 请尝试帮助先生...我检查了moto E4 Plus
  • @Mariyappan,检查异常可能是FileUriExposedException,如果是这样,请参考更新,否则,如果您发布遇到异常的问题,您将有更好的可见性。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-13
  • 2015-02-21
相关资源
最近更新 更多