数据库数据execl导出

/**
	 * 账号导出客户
	 * @param request
	 * @param response
	 * @param userId
	 * @param clientId
	 */
	@RequestMapping("/v_exportClient.do")
	public void exportClient(HttpServletRequest request , HttpServletResponse response , 
			String userId , String clientId){
		String jsonStr = "{\"result\":1}";
		try {
			List<TbOrgClient> list = tbOrgClientService.findClientByUserId(userId);
			//设置execl格式
			XSSFWorkbook workbook=new XSSFWorkbook();
			XSSFSheet sheet=workbook.createSheet("客户导出");
			XSSFRow row = sheet.createRow((short)0);
			XSSFCell cell=null;
			String[] title = new String[]{"客户id","客户名称","客户联系方式","客户手机号码","客户分组","客户类型","客户地址",
					"客户邮箱","客户证件类型","客户证件号码","客户类型","联系人","客户所属用户"};
			//设置execl表头
			for(int j=0;j<title.length;j++){
				cell=row.createCell((short)j);
				cell.setCellValue(title[j]);
			}
			//将数据导入execl表格
			for(int i=0;i<list.size();i++){//行
				row=sheet.createRow(i+1);//从第二行开始导入数据(第一行已被表头占用)
			    	cell=row.createCell(0);
			        cell.setCellValue(list.get(i).getId());
			        cell=row.createCell(1);
			        cell.setCellValue(list.get(i).getClientName());
			        cell=row.createCell(2);
			        cell.setCellValue(list.get(i).getClientContactWay());
			        cell=row.createCell(3);
			        cell.setCellValue(list.get(i).getClientMobile());
			        cell=row.createCell(4);
			        cell.setCellValue(list.get(i).getClientSelect());
			        cell=row.createCell(5);
			        cell.setCellValue(list.get(i).getClientType());
			        cell=row.createCell(6);
			        cell.setCellValue(list.get(i).getClientAddress());
			        cell=row.createCell(7);
			        cell.setCellValue(list.get(i).getClientEmail());
			        cell=row.createCell(8);
			        cell.setCellValue(list.get(i).getClientIdType());
			        cell=row.createCell(9);
			        cell.setCellValue(list.get(i).getClientIdNum());
			        cell=row.createCell(10);
			        cell.setCellValue(list.get(i).getUserType());
			        cell=row.createCell(11);
			        cell.setCellValue(list.get(i).getClientContactPerson());
			        cell=row.createCell(12);
			        cell.setCellValue(list.get(i).getUserId());
			}
			FileOutputStream fos = new FileOutputStream("D:\\test.xlsx");
			fos.flush();
			fos.close();
		    jsonStr = "{\"result\":0}";
            ResponseUtils.renderJson(response, jsonStr);
		} catch (Exception e) {
			 log.error("expostClient", e);
	            ResponseUtils.renderJson(response, jsonStr);
		}
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值