zl程序教程

您现在的位置是:首页 >  工具

当前栏目

jxl将html表单中数据写入到excel

ExcelHTML数据 表单 写入
2023-09-14 09:00:23 时间
     groupId net.sourceforge.jexcelapi /groupId          artifactId jxl /artifactId              version 2.6.12 l
     groupId net.sourceforge.jexcelapi /groupId          artifactId jxl /artifactId              version 2.6.12 /version        /dependency


后台代码如下:

  WritableWorkbook wwb = null;

  wwb=Workbook.createWorkbook(new File("c:\\1.xls"));//创建excel文件

  WritableSheet ws = wwb.createSheet("sheet1", 0);//创建一个可写入的工作表

      

  ws.setColumnView(0,25);

  ws.setColumnView(6,20);

  ws.setColumnView(9,20);

  ws.setColumnView(11,30);//设置列的宽度

  //设置表头

  ws.addCell(new Label(0,0,"商品图片"));

  ws.addCell(new Label(1,0,"商品名称"));

  ws.addCell(new Label(2,0,"市场价格"));

  ws.addCell(new Label(3,0,"会员价格"));

  ws.addCell(new Label(4,0,"被测人"));

  ws.addCell(new Label(5,0,"状态"));

  ws.addCell(new Label(6,0,"收样品时间"));

  ws.addCell(new Label(7,0,"收件人"));

  ws.addCell(new Label(8,0,"物流单号"));

  ws.addCell(new Label(9,0,"发报告时间"));

  ws.addCell(new Label(10,0,"物流单号"));

  ws.addCell(new Label(11,0,"检测报告"));

  //添加行数据,遍历需要写入excel的集合数据

  for (int i=1;i =odvs.size();i++){

   OrderDetailVo row=odvs.get(i-1);

   System.out.println(row); 

    ws.addCell(new Label(0,i,row.getThumbNail()));

    ws.addCell(new Label(1,i,row.getName()));

    ws.addCell(new Label(2,i,row.getMarketPrice().toString()));

    ws.addCell(new Label(3,i,row.getMemberPrice().toString()));

    ws.addCell(new Label(4,i,row.getPersonName()));

    ws.addCell(new Label(5,i,row.getStatus()));

    ws.addCell(new Label(6,i,row.getRecieveOrderDate().toString()));

    ws.addCell(new Label(7,i,row.getContact()));

    ws.addCell(new Label(8,i,row.getReceiveTrackNumber()));

    ws.addCell(new Label(9,i,row.getReportSendDate().toString()));

    ws.addCell(new Label(10,i,row.getReportTrackNumber()));

    ws.addCell(new Label(11,i,row.getReportDownloadPath()));

      

             wwb.write();//从内存中写入文件中

             wwb.close(); //关闭资源,释放内存

转换后的1.xls文档如下

wKioL1W8ev_SpjzHAAK68Tnkw0E682.jpg

参考文章:

http://pengfeicao521.iteye.com/blog/1415699

 

本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1680812


17、SpringBoot2.0中初始化数据和不校验 html 标签(十七) 我们在做测试的时候经常需要初始化导入一些数据,如何来处理呢?会有两种选择,一种是使用 Jpa,另外一种是 Spring JDBC 。两种方式各有区别下面来详细介绍。