2011年9月13日 星期二

android 手機寫入 Excel

關鍵程式碼:

private void open_book(){

    if(!Environment.getExternalStorageState().equals(Environment.MEDIA_REMOVED) ){

       

    try {

        File SDCardpath = Environment.getExternalStorageDirectory();

                File myDataPath = new File( SDCardpath.getAbsolutePath() + "/stay" );

               

        if( !myDataPath.exists()) myDataPath.mkdirs();

           

            //構建Workbook物件, 唯讀Workbook物件

                           //Method 1:創建可寫入的Excel工作薄

                          jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(new File(SDCardpath.getAbsolutePath() + "/stay/1234.xls"));

                           jxl.write.WritableSheet ws = wwb.createSheet("Test Sheet 1", 0);

                           jxl.write.Label labelC = new jxl.write.Label(0, 0, "This is a Label cell");



                           ws.addCell(labelC);

                      

                           wwb.write();

                           wwb.close();

          } catch (Exception e) {

        e.printStackTrace();

           }

Coding by Zick

參考:1.Android學習筆記 - 存取SD卡