<%@ 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 ");
}
%>
转载于:https://www.cnblogs.com/kunpengit/archive/2012/11/26/2788699.html
相关资源:Java使用POI导出Word文档