生成excel代码
来源:互联网 发布:视频日语翻译中文软件 编辑:程序博客网 时间:2024/06/08 16:48
这是一个action,前台只要给个onclick时间,调转到这个action就可以了。
public void commprinttjfx(HttpServletRequest req, HttpServletResponse res) {
WritableWorkbook workbook;
try {
// 创建excel
String fname = "当前时间段用户平均温度";
OutputStream os2 = res.getOutputStream();//取得输出流
res.reset();//清空输出流
//下面是对中文文件名的处理
res.setCharacterEncoding("UTF-8");
fname = java.net.URLEncoder.encode(fname, "UTF-8");
res.setHeader("Content-Disposition", "attachment; filename="+ new String(fname.getBytes("UTF-8"), "GBK") + ".xls");
res.setContentType("application/msexcel");//定义输出类型
OutputStream os = res.getOutputStream();
workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet("用户平均温度", 0);
//加入表头
Label xuhao = new Label(0, 0, "序号");
sheet.addCell(xuhao);
Label yonghu = new Label(1, 0, "用户");
sheet.addCell(yonghu);
Label IDma = new Label(2, 0, "ID码");
sheet.addCell(IDma);
Label jssj = new Label(3, 0, "接受数据时间");
sheet.addCell(jssj);
Label swwd = new Label(4, 0, "室外温度");
sheet.addCell(swwd);
Label szwd = new Label(5, 0, "设置温度");
sheet.addCell(szwd);
Label snwd = new Label(6, 0, "室内温度");
sheet.addCell(snwd);
Label fmzt = new Label(7, 0, "阀门状态");
sheet.addCell(fmzt);
Label gswd = new Label(8, 0, "供水温度");
sheet.addCell(gswd);
Label hswd = new Label(9, 0, "回水温度");
sheet.addCell(hswd);
Label jzmj = new Label(10, 0, "建筑面积");
sheet.addCell(jzmj);
Label rfh = new Label(11, 0, "热负荷");
sheet.addCell(rfh);
Label rzb = new Label(12, 0, "热指标");
sheet.addCell(rzb);
Label ftrl = new Label(13, 0, "分摊热量");
sheet.addCell(ftrl);
Label ftrf = new Label(14, 0, "分摊热费");
sheet.addCell(ftrf);
Label bjlx = new Label(15, 0, "报警类型");
sheet.addCell(bjlx);
//加入动态值
HttpSession session = req.getSession();
List<ContentVoBean> contenList=(List)session.getAttribute("sessionVoBeantjfx");
for (int i = 1; i < 9; i++) {
ContentVoBean c = contenList.get(i+1);
Label lab0 = new Label(0, i, Integer.toString(i));
sheet.addCell(lab0);
Label lab1 = new Label(1, i, c.getUserNumber());
sheet.addCell(lab1);
Label lab2 = new Label(2, i, c.getWenID());
sheet.addCell(lab2);
Label lab3 = new Label(3, i, c.getRevieTime());
sheet.addCell(lab3);
Label lab4 = new Label(4, i, c.getRoutdoorTemperature());
sheet.addCell(lab4);
Label lab5 = new Label(5, i, c.getSetTemperature());
sheet.addCell(lab5);
Label lab6 = new Label(6, i, c.getRealityTemperature());
sheet.addCell(lab6);
Label lab7 = new Label(7, i, c.getRvalveState());
sheet.addCell(lab7);
Label lab8 = new Label(8, i, c.getRwaterTemperature());
sheet.addCell(lab8);
Label lab9 = new Label(9, i, c.getRbackwaterTemperature());
sheet.addCell(lab9);
Label lab10 = new Label(10, i, c.getJzArea());
sheet.addCell(lab10);
Label lab11 = new Label(11, i, null);
sheet.addCell(lab11);
Label lab12 = new Label(12, i, null);
sheet.addCell(lab12);
Label lab13 = new Label(13, i, c.getFtrl());
sheet.addCell(lab13);
Label lab14 = new Label(14, i, c.getFtrf());
sheet.addCell(lab14);
Label lab15 = new Label(15, i, null);
sheet.addCell(lab15);
}
// 加入图片
WritableImage wi = new WritableImage(0,10,10,20,new File("c://222.png"));
sheet.addImage(wi);
//把创建的内容写入到输出流中,并关闭输出流
workbook.write();
workbook.close();
os.close();
req.getRequestDispatcher("background/content/tjfx.jsp").forward(req, res);
} catch (IOException e) {
e.printStackTrace();
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
}
- 生成excel代码
- 生成excel文件代码
- 纯cs代码生成Excel(不需要Excel)
- 一个直接生成EXCEL代码
- poi生成Excel的代码!
- poi生成excel代码示例
- 代码生成Excel导入模版
- js生成Excel的代码
- excel自动生成代码_1
- java生成Excel实例代码
- jxls 生成Excel的整套代码
- asp利用owc11生成excel,代码如下:
- ABAP动态生成代码上传EXCEL数据
- php生成excel文件示例代码
- java 生成EXCEL完整实现(附加代码)
- JAVA POI 生成EXCEL 通用代码
- java批量生成excel代码分享
- Java代码生成excel文件下载
- 对于酷盘、快盘等存储方式的一点看法
- java项目,从Oracle迁移到达梦数据库笔记
- 使用CFile类对文件进行读写
- Bootloader常用参数及在NAND FLASH里固化嵌入式系统
- 恢复BLOG
- 生成excel代码
- c#中执行存储过程
- 【项目经理之修炼(9)】《初级篇》谦虚也是可以修炼的
- asp.net 发送邮件代码
- 程序员的人际关系之探讨
- C#将递归算法转换为非递归算法提高性能
- 解决qq无声音的问题
- 每日设计模式——模板方法模式
- 怎样轻松获取积分