2013-08-16 48 views
1

我想能夠從我的android應用res \ raw文件夾複製一個excel文件到客戶端手機的內部存儲,並能夠從excel文件中檢索數據並更新根據需要在內部存儲器中使用excel文件。到目前爲止,所有我的是這樣的:從內部存儲Excel文件訪問android應用

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal ---將文件寫入到內部存儲和

http://www.vogella.com/articles/JavaExcel/article.html ---使用jexcel來檢索數據和編輯Excel文件

我可以」似乎可以將兩者聯繫起來。我該如何繼續實施這個應用程序?

由於

+0

我真的可以使用一些幫助這裏傢伙 –

+0

請試試這個ANS –

回答

2

對於讀取和寫入到使用Apache POI library

要一些樣品例如是有機器人通過讀寫Excel表單

1) Creating/Reading an Excel file in Android

2)Android Read Write EXCEL file using Apache POI

對於資產到SDcard請按照this link或使用此代碼。

package com.paresh.copyfileassetstoAssets; 

    import java.io.FileOutputStream; 
    import java.io.IOException; 
    import java.io.InputStream; 
    import java.io.OutputStream; 

    import android.app.Activity; 
    import android.content.res.AssetManager; 
    import android.os.Bundle; 
    import android.os.Environment; 
    import android.util.Log; 

    public class CopyFileAssetsToSDCardActivity extends Activity 
    { 
     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.main); 

      CopyAssets(); 
     } 

     private void CopyAssets() { 
      AssetManager assetManager = getAssets(); 
      String[] files = null; 
      try { 
       files = assetManager.list("Files"); 
      } catch (IOException e) { 
       Log.e("tag", e.getMessage()); 
      } 

      for(String filename : files) { 
       System.out.println("File name => "+filename); 
       InputStream in = null; 
       OutputStream out = null; 
       try { 
        in = assetManager.open("Files/"+filename); // if files resides inside the "Files" directory itself 
        out = new FileOutputStream(Environment.getExternalStorageDirectory().toString() +"/" + filename); 
        copyFile(in, out); 
        in.close(); 
        in = null; 
        out.flush(); 
        out.close(); 
        out = null; 
       } catch(Exception e) { 
        Log.e("tag", e.getMessage()); 
       } 
      } 
     } 
     private void copyFile(InputStream in, OutputStream out) throws IOException { 
      byte[] buffer = new byte[1024]; 
      int read; 
      while((read = in.read(buffer)) != -1){ 
       out.write(buffer, 0, read); 
      } 
     } 
    } 
+0

感謝您的幫助,但我遇到的問題是不同的。即使我現在已經將excel文件存儲到內部存儲器中,我需要從excel文件中檢索數據。我知道如何在內部存儲器中讀取文件,以及如何使用Apache POI庫從中獲取數據。需要幫助。謝謝。 –

+0

即使我正在尋找內部記憶,而不是外部,這個答案幫了很多!謝謝! –

相關問題