1

我希望能够将 excel 文件从我的 android 应用程序 res\raw 文件夹复制到客户端手机的内部存储中,并能够从 excel 文件中检索数据并根据需要更新内部存储中的 excel 文件。到目前为止,我所拥有的是:

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal --- 将文件写入内部存储和

http://www.vogella.com/articles/JavaExcel/article.html --- 使用 jexcel 从 excel 文件中检索数据和编辑

我似乎无法将两者联系起来。我该如何继续实施这个应用程序?

谢谢

4

1 回答 1

3

用于读写 使用Apache POI 库

对于一些示例示例,通过读取和写入 excel 表用于 android

1) 在 Android 中创建/读取 Excel 文件

2) Android 使用 Apache POI 读写 EXCEL 文件

对于到 SD 卡的资产,请点击此链接或使用此代码。

    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);
            }
        }
    }
于 2013-08-16T10:54:57.957 回答