weixin_44154472
weixin_44154472
采纳率0%
2018-12-27 23:31

android 实现excel的导出,没有报错,但在目标文件下,找不到应该导出的表

//导出
private void exportDataToExcel() {
ExportThread eThread = new ExportThread(this, excelFileName, new OnExcelReadWriteSuccess() {
@Override
public void onError(Exception e) {

        }
        @Override
        public void onReadSuccess(ArrayList<SmsData> readList) {

        }
        @Override
        public void onWriteSuccess() {
            String exportpath=Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"tongxunlu.xls";
            try{
                WritableWorkbook wb= Workbook.createWorkbook(new File(exportpath));
                WritableSheet ws=wb.createSheet("sheet",0);
                Label label=new Label(0,0,"name");
                Label label2=new Label(1,0,"phone");
                Label label3=new Label(2,0,"msg");
                Label label4=new Label(3,0,"issend");
                ws.addCell(label);
                ws.addCell(label2);
                ws.addCell(label3);
                ws.addCell(label4);
                for(int i=1;i<lists.size()+1;i++){
                    ws.addCell(new Label(
                            0,i,lists.get(i-1).getName()));
                    ws.addCell(new Label(1,i,lists.get(i-1).getPhone()));
                    ws.addCell(new Label(2,i,lists.get(i-1).getSms()));
                    if(lists.get(i-1).isSent()){
                        ws.addCell(new Label(3,i,"1"));
                    }else {
                        ws.addCell(new Label(3,i,"0"));
                    }
                }
                wb.write();
                wb.close();
                Toast.makeText(MainActivity.this,"导出成功"+exportpath,Toast.LENGTH_SHORT).show();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    });

}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • caozhy 从今以后生命中的每一秒都属于我爱的人 3年前

    调试输出下
    String exportpath=Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"tongxunlu.xls";
    这个路径对不对

    点赞 评论 复制链接分享

相关推荐