创建Execl、写入Execl数据、导入U盘
public WriteExcel(Context mContext){ this.mContext = mContext;}// 创建excel表public void createExcel(File file) { deleteExcel(file); WritableSheet ws = null; try { if (!file.exists()) { wwb = Workbook.createWorkbook(file);//创建表 ws = wwb.createSheet("sheet1", 0);//表名 页数 // 在指定单元格插入数据 Label lbl1 = new Label(0, 0, "标签1"); Label lbl2 = new Label(1, 0, "标签2"); Label lbl3 = new Label(2, 0, "标签3"); Label lbl4 = new Label(3, 0, "标签4"); ws.addCell(lbl1); ws.addCell(lbl2); ws.addCell(lbl3); ws.addCell(lbl4); // 从内存中写入文件中 wwb.write(); wwb.close(); } } catch (Exception e) { e.printStackTrace(); }} /**向Execl写入数据 * @Param ls List
发送带附件的邮件
private void postEmail(String emailPath){ SimpleDateFormat fmat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time=fmat.format(new Date(System.currentTimeMillis())); //打开execl文件 String path=getExcelDir()+ File.separator+"CardInfo.xls"; File file = new File(path); if(file.exists()){ Intent email = new Intent(android.content.Intent.ACTION_SEND); email.setType("application/octet-stream"); //邮件接收者(数组,可以是多位接收者) String[] emailReciver = new String[]{emailPath}; String emailTitle = "信息_"+time; String emailContent = "核验信息"; //设置邮件地址 email.putExtra(android.content.Intent.EXTRA_EMAIL, emailReciver); //设置邮件标题 email.putExtra(android.content.Intent.EXTRA_SUBJECT, emailTitle); //设置发送的内容 email.putExtra(android.content.Intent.EXTRA_TEXT, emailContent); //附件 email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); //调用系统的邮件系统 mContext.startActivity(Intent.createChooser(email, "请选择邮件发送软件")); }}
邮箱格式检查的正则表达式
public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";