2011-07-08 11 views
4

Excelファイルをsdcardにダウンロードしました。私のアプリでファイルを開き、それを処理したい。 アンドロイドでExcelファイルを開く方法や意図はありますか? IandroidでExcelファイルを開く方法

+0

ダウン投票のためのダウン投票の理由を言及してください。 –

+1

私はdownvotingしていませんが、Excelファイルを開くためのアプリケーションを起動するかどうか、またはアプリケーションでファイルを開いて処理するかどうかを説明する必要があります(私は前者を推測しています) –

+0

開けたいですか?私のアプリのファイルとそれを処理する –

答えて

0

詳しいことはできますか? あなたはここに、ファイルを使用してSDカードからファイルをエクセル読みたい場合は、コード

File root = Environment.getExternalStorageDirectory(); 
File excelFile = new File(root, "filename.xlsx"); 
2

は、任意のファイル(エクセルだけではなく)を開くために使用することができ、コードのこの部分を使用しています。

一般的な考え方は、Intentが処理できるファイルのMIMEタイプに基づいており、次にそれらを開始することですIntent。システムがそれを処理するための意図を持たないか、または複数のインテントを持つ可能性があります。とにかく、ここで一般的な方向です:

指定したファイル名

public String getMimeType(String filename) 
{ 
    String extension = FileUtils.getExtension(filename); 
    // Let's check the official map first. Webkit has a nice extension-to-MIME map. 
    // Be sure to remove the first character from the extension, which is the "." character. 
    if (extension.length() > 0) 
    { 
     String webkitMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1)); 
     if (webkitMimeType != null) 
      return webkitMimeType; 
    } 
    return "*/*"; 
} 

のMIMEタイプは、次に指定されたMIMEタイプ

public Intent getDefaultViewIntent(Uri uri) 
{ 
    PackageManager pm = this.getPackageManager(); 
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    // Let's probe the intent exactly in the same way as the VIEW action 
    String name=(new File(uri.getPath())).getName(); 
    intent.setDataAndType(uri, this.getMimeType(name)); 
    final List<ResolveInfo> lri = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); 
    if(lri.size() > 0) 
     return intent; 
    return null; 
} 

そして、最後のステップとしてを処理するデフォルトの意図は、ちょうどgetDefaultViewIntent()

によって返さ Intentを開始ゲット
0

Android上で動作するかどうかわかりません(必要以上に大げさになるかもしれません)。しかし、私はリストしたいと思いましたApache POI - Excelを含むMicrosoft Officeドキュメントを操作するためのJava API。

7

は、以下のコードを言及してみてください使用します。

File file = new File(Environment.getExternalStorageDirectory()+ "/filepath/" + filename); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(file),"application/vnd.ms-excel"); 
startActivity(intent); 
1
Uri path = Uri.fromFile(file); 
Intent excelIntent = new Intent(Intent.ACTION_VIEW); 
excelIntent.setDataAndType(path , "application/vnd.ms-excel"); 
excelIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
try { 
    startActivity(excelIntent); 
} catch (ActivityNotFoundException e) { 
    Toast.makeText(EmptyBlindDocumentShow.this,"No Application available to viewExcel", Toast.LENGTH_SHORT).show(); 
} 

以上の基準ここをクリックhttp://androiddhina.blogspot.in/2015/07/how-to-view-excel-in-android-application.html

関連する問題