zoukankan      html  css  js  c++  java
  • poi导出

    <%@ page contentType="application/vnd.ms-excel" language="java" import="java.util.*,org.apache.poi.hssf.usermodel.HSSFCell,org.apache.poi.hssf.usermodel.HSSFRow,org.apache.poi.hssf.usermodel.HSSFSheet,org.apache.poi.hssf.usermodel.HSSFWorkbook,java.io.*,cn.com.starit.inas.persistence.dto.statisAly.StatisAlyJFDto" pageEncoding="utf-8"%>
    <%@page import="org.apache.poi.hssf.record.aggregates.RowRecordsAggregate"%>
    <%@page import="org.apache.poi.hssf.util.Region"%><%
    response.setHeader("Content-Disposition","attachment;filename=excel.xls");//指定下载的文件名
    response.setContentType("application/vnd.ms-excel"); 
    List<StatisAlyJFDto> listResult =(List<StatisAlyJFDto>) request.getAttribute("listResult");
    StatisAlyJFDto temp =new StatisAlyJFDto();
    temp =(StatisAlyJFDto)listResult.get(0);
    HSSFWorkbook wb=new HSSFWorkbook();
      HSSFSheet sheet1=wb.createSheet("sheet1");
      sheet1.setColumnWidth((short)0,(short)5000);
      sheet1.setColumnWidth((short)1,(short)3000);
      sheet1.setColumnWidth((short)2,(short)3000);
      sheet1.setColumnWidth((short)3,(short)3000);
      sheet1.setColumnWidth((short)4,(short)3000);
      
      HSSFRow row=sheet1.createRow((short)0);
      row.setHeightInPoints(20);
      HSSFCell cell=row.createCell((short)0);
      cell.setCellValue("C网停复机效率统计");
      row.createCell((short)1).setCellValue("C网复机");
      row.createCell((short)2).setCellValue("C网复机");
      row.createCell((short)3).setCellValue("C网停机");
      row.createCell((short)4).setCellValue("C网停机");
      sheet1.addMergedRegion(new Region((short)0, (short)0, (short)1, (short)0));
      sheet1.addMergedRegion(new Region((short)0, (short)1, (short)0, (short)2));
      sheet1.addMergedRegion(new Region((short)0, (short)3, (short)0, (short)4));
      
      row=sheet1.createRow((short)1);
      row.setHeightInPoints(20);
      row.createCell((short)1).setCellValue("工单数");
      row.createCell((short)2).setCellValue("占比");
      row.createCell((short)3).setCellValue("工单数");
      row.createCell((short)4).setCellValue("占比");
      
      
      row=sheet1.createRow((short)2);
      row.setHeightInPoints(20);
      cell=row.createCell((short)0);
      cell.setCellValue("订单总量");
      row.createCell((short)1).setCellValue(temp.getTotal());
      row.createCell((short)2).setCellValue(temp.getTotal());
      row.createCell((short)3).setCellValue(temp.getTotal2());
      row.createCell((short)4).setCellValue(temp.getTotal2());
      sheet1.addMergedRegion(new Region((short)2, (short)1, (short)2, (short)2));
      sheet1.addMergedRegion(new Region((short)2, (short)3, (short)2, (short)4));
      
      row=sheet1.createRow((short)3);
      row.setHeightInPoints(20);
      cell=row.createCell((short)0);
      cell.setCellValue("1分钟内");
      row.createCell((short)1).setCellValue(temp.getZero2one());
      row.createCell((short)2).setCellValue(temp.getZero2onelv());
      row.createCell((short)3).setCellValue(temp.getZero2onelv2());
      row.createCell((short)4).setCellValue(temp.getZero2onelv2());
      
      row=sheet1.createRow((short)4);
      row.setHeightInPoints(20);
      cell=row.createCell((short)0);
      cell.setCellValue("1-2分钟内");
      row.createCell((short)1).setCellValue(temp.getOne2two());
      row.createCell((short)2).setCellValue(temp.getOne2twolv());
      row.createCell((short)3).setCellValue(temp.getOne2two2());
      row.createCell((short)4).setCellValue(temp.getOne2twolv2());
      
      row=sheet1.createRow((short)5);
      row.setHeightInPoints(20);
      cell=row.createCell((short)0);
      cell.setCellValue("2-3分钟内");
      row.createCell((short)1).setCellValue(temp.getTwo2three());
      row.createCell((short)2).setCellValue(temp.getTwo2threelv());
      row.createCell((short)3).setCellValue(temp.getTwo2three2());
      row.createCell((short)4).setCellValue(temp.getTwo2threelv2());
      
      row=sheet1.createRow((short)6);
      row.setHeightInPoints(20);
      cell=row.createCell((short)0);
      cell.setCellValue("3-5分钟内");
      row.createCell((short)1).setCellValue(temp.getThree2five());
      row.createCell((short)2).setCellValue(temp.getThree2fivelv());
      row.createCell((short)3).setCellValue(temp.getThree2five2());
      row.createCell((short)4).setCellValue(temp.getThree2fivelv2());
      
      row=sheet1.createRow((short)7);
      row.setHeightInPoints(20);
      cell=row.createCell((short)0);
      cell.setCellValue("5-10分钟内");
      row.createCell((short)1).setCellValue(temp.getFive2ten());
      row.createCell((short)2).setCellValue(temp.getFive2tenlv());
      row.createCell((short)3).setCellValue(temp.getFive2ten2());
      row.createCell((short)4).setCellValue(temp.getFive2tenlv2());
      
      row=sheet1.createRow((short)8);
      row.setHeightInPoints(20);
      cell=row.createCell((short)0);
      cell.setCellValue("10分钟以上");
      row.createCell((short)1).setCellValue(temp.getOverten());
      row.createCell((short)2).setCellValue(temp.getOvertenlv());
      row.createCell((short)3).setCellValue(temp.getOverten2());
      row.createCell((short)4).setCellValue(temp.getOvertenlv2());
      //FileOutputStream fileout=new FileOutputStream("workbook.xls");
    
      OutputStream output = response.getOutputStream(); 
      try   { 
             output.flush(); 
             wb.write(output); 
             output.close();
     }   catch   (IOException   e)   { 
             e.printStackTrace(); 
             System.out.println( "Output   is   closed "); 
     } 
     
    %>
  • 相关阅读:
    Heterogeneity Wins
    Android使用ImageView显示网络图片
    Android OOM的解决方式
    洛谷P3390 【模板】矩阵快速幂
    CF732D. Exams[二分答案 贪心]
    洛谷P3388 【模板】割点
    POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
    NOI2001|POJ1182食物链[种类并查集 向量]
    HDU3038 How Many Answers Are Wrong[带权并查集]
    NOIP2010关押罪犯[并查集|二分答案+二分图染色 | 种类并查集]
  • 原文地址:https://www.cnblogs.com/kunpengit/p/2788699.html
Copyright © 2011-2022 走看看