1

Android アプリの res\raw フォルダーから Excel ファイルをクライアントの電話の内部ストレージにコピーし、必要に応じて Excel ファイルからデータを取得し、内部ストレージの Excel ファイルを更新できるようにしたいと考えています。これまでのところ、私が持っているのはこれだけです:

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal --- ファイルを内部ストレージに書き込み、

http://www.vogella.com/articles/JavaExcel/article.html --- jexcel を使用してデータを取得し、Excel ファイルを編集する

2つをリンクすることはできないようです。このアプリを実装するにはどうすればよいですか?

ありがとう

4

1 に答える 1

3

For Read and Write To use Apache POI library

To some sample example is there for android through read and write excel sheet

1) Creating/Reading an Excel file in Android

2) Android Read Write EXCEL file using Apache POI

For Assets to SDcard Follow this link Or use this code.

    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 に答える