表格的导入

来源:互联网 发布:ubuntu14.04安装mysql 编辑:程序博客网 时间:2024/03/28 21:57
@Action(value = "appAdressExcel", results = { @Result(type = "json", params = {"contentType", "text/html", "root", "result" }) })public String appAdressExcel() throws IOException {//设置表格命名方式String xlsFileName = "appAdressExcel"+ Constants.df6.format(new Date()).toString() + ".xls";//设置表格存储路径String xlsFilePath = "/ISIC_FILE/appAdressExcel/";// 导出文件的路径String xlsFile = "/ISIC_FILE/appAdressExcel/" + xlsFileName;// 导出文件的路径File file = new File(xlsFilePath);//判断file是否是一个目录 是则返回trueif (!file.isDirectory()) {//创建目录file.mkdirs();}//创建文件输出流FileOutputStream fos = new FileOutputStream(xlsFile);// 产生工作簿对象HSSFWorkbook workbook = new HSSFWorkbook(); // 产生工作表对象HSSFSheet sheet = workbook.createSheet(); //设置工作表名字workbook.setSheetName(0, "affiliateSheet");try {//创建表头HSSFRow row0 = sheet.createRow((short) 0);cteateCell(row0, 0, "卡片类型");cteateCell(row0, 1, "卡号");cteateCell(row0, 2, "状态");cteateCell(row0, 3, "申请人名(EN)");cteateCell(row0, 4, "申请人名(CN)");cteateCell(row0, 5, "手机号码");cteateCell(row0, 6, "邮编");cteateCell(row0, 7, "地址");cteateCell(row0, 8, "电子邮件");cteateCell(row0, 9, "学校名(EN)");cteateCell(row0, 10, "学校名(CN)");cteateCell(row0, 11, "生日");cteateCell(row0, 12, "性别");//获取输出对象List<IsicApplicant> alist = applicateService.getIsicApplicationByIds(ids);             for(int i=0;i<alist.size();i++){             IsicApplicant a=alist.get(i);            HSSFRow row = sheet.createRow((short) (i+1));        cteateCell(row, 0, getCardType(a.getCardType()));        cteateCell(row, 1, a.getCardNumber());        cteateCell(row, 2, a.ShowStatus());        cteateCell(row, 3, a.getApplicantName());        cteateCell(row, 4, a.getApplicantNameCn());        cteateCell(row, 5, a.getMobile());        cteateCell(row, 6, a.getZipcode());        cteateCell(row, 7, a.getAddress());        cteateCell(row, 8, a.getEmail());        cteateCell(row, 9, a.getSchoolName());        cteateCell(row, 10,a.getSchoolNameCn());        cteateCell(row, 11, a.getBirthday());        cteateCell(row, 12, a.getGender());             }fos.flush();workbook.write(fos);fos.close();result = "http://" + request.getServerName()+ "/viewResourcesAction/appAdressExcel/" + xlsFileName;System.out.println(result);} catch (IOException e) {fos.close();result = "Excel export fails";e.printStackTrace();}System.out.println("文件生成...");return SUCCESS;}



引入poi.jar

原创粉丝点击