jxl将html表单中数据写入到excel_html/css_WEB-ITnose
程序员文章站
2022-04-16 12:34:29
...
首先下载jxl-2.6.12.jar或者在maven中添加
net.sourceforge.jexcelapi jxl 2.6.12
后台代码如下:
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转换后的1.xls文档如下
参考文章:
http://pengfeicao521.iteye.com/blog/1415699