首页 >web前端 >html教程 >jxl将html表单中数据写入到excel_html/css_WEB-ITnose

jxl将html表单中数据写入到excel_html/css_WEB-ITnose

WBOY
WBOY原创
2016-06-24 11:39:481568浏览

首先下载jxl-2.6.12.jar或者在maven中添加

 <dependency>         <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(11,30);//设置列的宽度  ws.setColumnView(0,25);  ws.setColumnView(6,20);  ws.setColumnView(9,20);  //设置表头  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文档如下

参考文章:

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

 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn