java 导出excel 实现

Imp 实现层
 @Override
 public HSSFWorkbook exportExcel(List<DeclstateList> declstateList)throws Exception {
  
 HSSFWorkbook wb = new HSSFWorkbook();
 // 建立新的sheet对象(excel的表单)
 HSSFSheet sheet = wb.createSheet("Sheet");
 HSSFRow title = sheet.createRow(0);
 HSSFCell cell_1 = title.createCell(0);
 cell_1.setCellValue("订单编号");
  
 HSSFCell cell_2 = title.createCell(1);
 cell_2.setCellValue("PO No.");
  
 HSSFCell cell_3 = title.createCell(2);
 cell_3.setCellValue("发票号");
  
 HSSFCell cell_4 = title.createCell(3);
 cell_4.setCellValue("供应商");
  
 HSSFCell cell_5 = title.createCell(4);
 cell_5.setCellValue("使用方");
  
 HSSFCell cell_6 = title.createCell(5);
 cell_6.setCellValue("贸易条款");
  
 HSSFCell cell_7 = title.createCell(6);
 cell_7.setCellValue("运输方式");
  
 HSSFCell cell_8 = title.createCell(7);
 cell_8.setCellValue("主单号");
  
 HSSFCell cell_9 = title.createCell(8);
 cell_9.setCellValue("分单号");
  
 HSSFCell cell_10 = title.createCell(9);
 cell_10.setCellValue("航班号/船名航次");
  
 HSSFCell cell_11 = title.createCell(10);
 cell_11.setCellValue("报关单号");
  
 HSSFCell cell_12 = title.createCell(11);
 cell_12.setCellValue("贸易方式");
  
 HSSFCell cell_13 = title.createCell(12);
 cell_13.setCellValue("件数");
  
 HSSFCell cell_14 = title.createCell(13);
 cell_14.setCellValue("毛重");
  
 HSSFCell cell_15 = title.createCell(14);
 cell_15.setCellValue("体积");
  
 HSSFCell cell_16 = title.createCell(15);
 cell_16.setCellValue("货值");
  
 HSSFCell cell_17 = title.createCell(16);
 cell_17.setCellValue("币种");
  
 HSSFCell cell_18 = title.createCell(17);
 cell_18.setCellValue("运费申报");
  
 HSSFCell cell_19 = title.createCell(18);
 cell_19.setCellValue("启运国");
  
 HSSFCell cell_20 = title.createCell(19);
 cell_20.setCellValue("目的港");
  
 HSSFCell cell_21 = title.createCell(20);
 cell_21.setCellValue("抵港时间");
  
 HSSFCell cell_22 = title.createCell(21);
 cell_22.setCellValue("单证准备");
  
 HSSFCell cell_23 = title.createCell(22);
 cell_23.setCellValue("单证完成");
  
 HSSFCell cell_24 = title.createCell(23);
 cell_24.setCellValue("申报时间");
  
 HSSFCell cell_25 = title.createCell(24);
 cell_25.setCellValue("出税时间");
  
 HSSFCell cell_26 = title.createCell(25);
 cell_26.setCellValue("付税时间");
  
 HSSFCell cell_27 = title.createCell(26);
 cell_27.setCellValue("海关查验");
  
 HSSFCell cell_28 = title.createCell(27);
 cell_28.setCellValue("商检查验");
  
 HSSFCell cell_29 = title.createCell(28);
 cell_29.setCellValue("放行时间");
  
 HSSFCell cell_30 = title.createCell(29);
 cell_30.setCellValue("运输时间");
  
 HSSFCell cell_31 = title.createCell(30);
 cell_31.setCellValue("其他-取证时间");
  
 HSSFCell cell_32 = title.createCell(31);
 cell_32.setCellValue("进口关税(CNY)");
  
 HSSFCell cell_33 = title.createCell(32);
 cell_33.setCellValue("进口增值税(CNY)");
  
 HSSFCell cell_34 = title.createCell(33);
 cell_34.setCellValue("其他税");
  
 HSSFCell cell_35 = title.createCell(34);
 cell_35.setCellValue("汇率");
  
 HSSFCell cell_36 = title.createCell(35);
 cell_36.setCellValue("备注");
  
 int lineNum = 1;//行数
 for (DeclstateList rcd : declstateList) {
 HSSFRow dataRow = sheet.createRow(lineNum);
 //订单编号
 HSSFCell cell_line_1 = dataRow.createCell(0);
 cell_line_1.setCellValue(rcd.getOrderNo());
 //PO No.
 HSSFCell cell_line_2 = dataRow.createCell(1);
 cell_line_2.setCellValue(rcd.getPoNo());
  
 //发票号
 HSSFCell cell_line_3 = dataRow.createCell(2);
 cell_line_3.setCellValue(rcd.getInvoiceNo());
  
 //供应商
 HSSFCell cell_line_4 = dataRow.createCell(3);
 cell_line_4.setCellValue(rcd.getSupplier());
  
 //使用方
 HSSFCell cell_line_5 = dataRow.createCell(4);
 cell_line_5.setCellValue(rcd.getUserside());
  
 //贸易条款
 HSSFCell cell_line_6 = dataRow.createCell(5);
 cell_line_6.setCellValue(rcd.getTradeClause());
  
 //运输方式
 HSSFCell cell_line_7 = dataRow.createCell(6);
 cell_line_7.setCellValue(rcd.getTypeShipping());
  
 //主单号
 HSSFCell cell_line_8 = dataRow.createCell(7);
 cell_line_8.setCellValue(rcd.getMainNo());
  
 //分单号
 HSSFCell cell_line_9 = dataRow.createCell(8);
 cell_line_9.setCellValue(rcd.getPartsNo());
  
 //航班号/船名航次
 HSSFCell cell_line_10 = dataRow.createCell(9);
 cell_line_10.setCellValue(rcd.getFlightNumber());
  
 //报关单号
 HSSFCell cell_line_11 = dataRow.createCell(10);
 cell_line_11.setCellValue(rcd.getDeclNo());
  
 //贸易方式
 HSSFCell cell_line_12 = dataRow.createCell(11);
 cell_line_12.setCellValue(rcd.getTradeType());
  
 //件数
 HSSFCell cell_line_13 = dataRow.createCell(12);
 cell_line_13.setCellValue(rcd.getPackNo());
  
 //毛重
 HSSFCell cell_line_14 = dataRow.createCell(13);
 cell_line_14.setCellValue(rcd.getGrossWt());
  
 //体积
 HSSFCell cell_line_15 = dataRow.createCell(14);
 cell_line_15.setCellValue(rcd.getVolume());
  
 //货值
 HSSFCell cell_line_16 = dataRow.createCell(15);
 cell_line_16.setCellValue(rcd.getTotal());
  
 //币种
 HSSFCell cell_line_17 = dataRow.createCell(16);
 cell_line_17.setCellValue(rcd.getCurrencyCode());
  
 //运费申报
 HSSFCell cell_line_18 = dataRow.createCell(17);
 cell_line_18.setCellValue(rcd.getFreightDeclrartion());
  
 //启运国
 HSSFCell cell_line_19 = dataRow.createCell(18);
 cell_line_19.setCellValue(rcd.getTradeCountry());
  
 //目的港
 HSSFCell cell_line_20 = dataRow.createCell(19);
 cell_line_20.setCellValue(rcd.getDistinatePort());
  
 //抵港时间
 HSSFCell cell_line_21 = dataRow.createCell(20);
 cell_line_21.setCellValue(rcd.getArrivalTime());
  
 //单证准备
 HSSFCell cell_line_22 = dataRow.createCell(21);
 cell_line_22.setCellValue(rcd.getDocumentPrepara());
  
 //单证完成
 HSSFCell cell_line_23 = dataRow.createCell(22);
 cell_line_23.setCellValue(rcd.getDocumentFinish());
  
 //申报时间
 HSSFCell cell_line_24 = dataRow.createCell(23);
 cell_line_24.setCellValue(rcd.getDeclTime());
  
 //出税时间
 HSSFCell cell_line_25 = dataRow.createCell(24);
 cell_line_25.setCellValue(rcd.getTaxTime());
  
 //付税时间
 HSSFCell cell_line_26 = dataRow.createCell(25);
 cell_line_26.setCellValue(rcd.getTaxPay());
  
 //海关查验
 HSSFCell cell_line_27 = dataRow.createCell(26);
 cell_line_27.setCellValue(rcd.getCustomsInspection());
  
 //商检查验
 HSSFCell cell_line_28 = dataRow.createCell(27);
 cell_line_28.setCellValue(rcd.getCommodityInspection());
  
 //放行时间
 HSSFCell cell_line_29 = dataRow.createCell(28);
 cell_line_29.setCellValue(rcd.getReleaseTime());
  
 //运输时间
 HSSFCell cell_line_30 = dataRow.createCell(29);
 cell_line_30.setCellValue(rcd.getTransportation());
  
 //其他-取证时间
 HSSFCell cell_line_31 = dataRow.createCell(30);
 cell_line_31.setCellValue(rcd.getOtherTime());
  
 //进口关税(CNY)
 HSSFCell cell_line_32 = dataRow.createCell(31);
 cell_line_32.setCellValue(rcd.getTariffFavored());
  
 //进口增值税(CNY)
 HSSFCell cell_line_33 = dataRow.createCell(32);
 cell_line_33.setCellValue(rcd.getVat());
  
 //其他税
 HSSFCell cell_line_34 = dataRow.createCell(33);
 cell_line_34.setCellValue(rcd.getOtherTax());
  
 //汇率
 HSSFCell cell_line_35 = dataRow.createCell(34);
 cell_line_35.setCellValue(rcd.getRate());
  
 //备注
 HSSFCell cell_line_36 = dataRow.createCell(35);
 cell_line_36.setCellValue(rcd.getRemarks());
  
 lineNum++;
 }
 return wb;
 }
 Contoller 控制层
  
 @ResponseBody
 方法
 response.setContentType("application/ms-excel;charset=UTF-8");
 response.setHeader("Content-Disposition","attachment;filename=".concat(String.valueOf(URLEncoder.encode("统计分析" + ".xls", "UTF-8"))));
  
 HSSFWorkbook wb = declstateListService.exportExcel(decllistPage);
 OutputStream out = response.getOutputStream();
 wb.write(out);
 out.close();
  
  
 service 层
  
 public HSSFWorkbook exportExcel(List<DeclstateList> declstateList) throws Exception;
  
  
 前台 window.location.href="url";
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值