zoukankan      html  css  js  c++  java
  • android 学习

    今天完成了把信息导出到表格中

     private void exportExcel(Context context) {
            String path = Environment.getExternalStorageDirectory().getPath() + "/test3";
            File file = new File(path);
            if (!file.exists()) {
                file.mkdirs();
            }
            File files = new File(file.getPath()+"/"+"text3.xls");
            if (!files.exists()) {// 文件存在返回false
                try {
                    files.createNewFile();//创建文件
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            Toast.makeText(MainActivity.this, "存储到"+files.getPath(), Toast.LENGTH_SHORT).show();
            initExcel(files);
        }//创建表格
    
    
    
        public  void initExcel(File filePath){
    
            try {
                WritableWorkbook workbook = null;
                if (!filePath.exists()) {
                    filePath.createNewFile();
                }
    
    
    
    
                workbook = Workbook.createWorkbook(filePath);
                WritableSheet sheet = workbook.createSheet("test3",0);
                sheet.mergeCells(0,0,6,0);
                Label header = new Label(0,0,"学生14天健康情况登记表");
                sheet.addCell(header);
                sheet.mergeCells(0,1,3,1);
                sheet.addCell(new Label(0,1,"单位名称:"+cla));
    
                sheet.mergeCells(4,1,6,1);
                sheet.addCell(new Label(4,1,"填表日期:"+getDate()));
    
                sheet.addCell(new Label(0,2,"姓名"));
                sheet.addCell(new Label(1,2,name));
                sheet.mergeCells(1,2,3,2);
                sheet.addCell(new Label(4,2,"学号:"));
                sheet.addCell(new Label(5,2,xuehao));
                sheet.mergeCells(5,2,6,2);
                sheet.addCell(new Label(0,3,"目前健康状况:"));
                sheet.mergeCells(1,3,3,3);
                sheet.addCell(new Label(1,3,"正常"));
                sheet.addCell(new Label(4,3,"手机号"));
                sheet.addCell(new Label(5,3,phone));
                sheet.mergeCells(5,3,6,3);
                sheet.mergeCells(0,4,6,4);
                sheet.addCell(new Label(0,4,"每日体温、健康状况监测(周期14天)"));
                String [] colName = {"日期","每日体温℃","健康状况","当日所在地","备注"};
                sheet.mergeCells(3,5,4,5);
                sheet.mergeCells(5,5,6,5);
                for (int col=0;col<3;col++){
                    sheet.addCell(new Label(col, 5, colName[col]));
                }
                sheet.addCell(new Label(3, 5, colName[3]));
                sheet.addCell(new Label(5, 5, colName[4]));
    
                int j=6;
                dbHelper=new DatabaseHelper(this,"TTList3.db",null,3);
                SQLiteDatabase db2=dbHelper.getWritableDatabase();
                Cursor cursor2 = db2.query("TTList3", null, "姓名=?", new String[]{name}, null, null, null);//读取数据库所有信息
                // Cursor cursor=db.query("tt",null,"专业=?",new String[]{"软件工程"},
                //null,null,null);//读取数据库里面专业是软件工程的所有信息
                if(cursor2.moveToFirst()){
                    do{
                        String name=cursor2.getString(cursor2.getColumnIndex("姓名"));
                        String tt=cursor2.getString(cursor2.getColumnIndex("体温"));
                        String time=cursor2.getString(cursor2.getColumnIndex("日期时间"));
                        String location=cursor2.getString(cursor2.getColumnIndex("所在地"));
    
                        String str = time.substring(0, time.indexOf(" "));
                        sheet.addCell(new Label(0,j,str));
                        sheet.addCell(new Label(1,j,tt));
                        double k = Double.parseDouble(tt);
                        if (k < 37.3 &&k > 35) {
                            sheet.addCell(new Label(2,j,"正常"));
                        } else {
                            sheet.addCell(new Label(2,j,"异常"));
                        }
                        sheet.addCell(new Label(3,j,location));
                        j++;
                    }while (cursor2.moveToNext());
                }
                cursor2.close();
    
    
    
                sheet.mergeCells(0,20,6,20);
                sheet.addCell(new Label(0,20,"本人承诺:自觉履行疫情防控责任和义务,保证以上填报信息全部属实,如有隐瞒,自愿承担相应法律后果。"));
                sheet.mergeCells(0,21,1,21);
                sheet.addCell(new Label(0,21,"本人签字:"));
                sheet.mergeCells(2,21,3,21);
                sheet.addCell(new Label(4,21,"签字日期:"));
                sheet.mergeCells(5,21,6,21);
                workbook.write();
                workbook.close();
    
            } catch (IOException e) {
                e.printStackTrace();
            } catch (RowsExceededException e) {
                e.printStackTrace();
            } catch (WriteException e) {
                e.printStackTrace();
            }
    
        }//对表格处理

                                                                                                                                                                                                                                                                                                                                                                                                               

  • 相关阅读:
    快速排序
    优先队列
    堆排序
    树、二叉树基础
    分治法
    递归算法详细分析
    算法基础
    Linux文件系统详解
    fs/ext2/inode.c相关函数注释
    块设备的读流程分析
  • 原文地址:https://www.cnblogs.com/Nojava/p/14908028.html
Copyright © 2011-2022 走看看