/**
* 账号导出客户
* @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);
}
}
数据库数据execl导出
最新推荐文章于 2024-09-15 19:46:31 发布