【android學習記錄】excal的讀取

compile 'com.hynnet:jxl:2.6.12.1'
public void FileTest(){

    try{

        //讀取assets目錄下的文件
        inputStream=this.getAssets().open("打開的文件名");

        //臨時文件 第二個參數爲文件名
        File file=new File(this.getCacheDir(),"test.xls");


        //將輸入流讀取成一個文件方便使用
        outputStream=new FileOutputStream(file);
        byte[] bytes=new byte[1024];
        int len;

        while ((len=inputStream.read(bytes))>0){
            outputStream.write(bytes,0,len);
        }

        outputStream.close();
        inputStream.close();

    }catch (IOException e){
        e.printStackTrace();
    }

}


private void ExcalTest(File file){

    try{

        Workbook workbook=Workbook.getWorkbook(file);

        Sheet[]sheets=workbook.getSheets();//得到所有的工作表

        for(int i=0;i<sheets.length;i++){
            Sheet sheet=workbook.getSheet(i);
            int Rows=sheet.getRows();//得到當前行數
            int Cols=sheet.getColumns();//得到當前的列數

            //按列讀取
            for(int j=0;j<Cols;j++){
                for(int k=0;k<Rows;k++){
                    //kj列的結果
                    String content=sheet.getCell(j,k).getContents();
                }
            }


        }



    }catch (IOException e){
        e.printStackTrace();
    }catch (BiffException e){
        e.printStackTrace();
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章