XSSFWorkbook wb = new XSSFWorkbook();
// 工作表
XSSFSheet sheet = wb.createSheet("车辆使用情况统计");
XSSFCellStyle style = wb.createCellStyle();
style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);

// 第一季度
XSSFRow row1 = sheet.createRow(0);
row1.setHeight((short)500);
XSSFCell title1 = row1.createCell(0);
title1.setCellStyle(style);
title1.setCellValue("全年");
CellRangeAddress regiontitletitle1 = new CellRangeAddress(0, 1, 0, 1);
sheet.addMergedRegion(regiontitletitle1);

XSSFRow row_2 = sheet.createRow(2);
row_2.setHeight((short)500);
XSSFCell title2 = row_2.createCell(0);
title2.setCellStyle(style);
title2.setCellValue("里程表数(Km)");
CellRangeAddress regiontitletitle2 = new CellRangeAddress(2, 2, 0, 1);
sheet.addMergedRegion(regiontitletitle2);
//第二行数据
Cell(row_2, style, sheet, clsyqkArray);
XSSFRow row_3 = sheet.createRow(3);
row_3.setHeight((short)500);
XSSFCell title3 = row_3.createCell(0);
title3.setCellStyle(style);
title3.setCellValue("行驶里程(Km)");
CellRangeAddress regiontitletitle3 = new CellRangeAddress(3, 3, 0, 1);
sheet.addMergedRegion(regiontitletitle3);
//第三行数据
Cell(row_3, style, sheet, clsyqkArray);
XSSFRow row_4 = sheet.createRow(4);
row_4.setHeight((short)500);
XSSFCell title4 = row_4.createCell(0);
title4.setCellStyle(style);
title4.setCellValue("耗油量(L)");
CellRangeAddress regiontitletitle4 = new CellRangeAddress(4, 4, 0, 1);
sheet.addMergedRegion(regiontitletitle4);
Cell(row_4, style, sheet, clsyqkArray);
XSSFRow row_5 = sheet.createRow(5);
row_5.setHeight((short)500);
XSSFCell title5 = row_5.createCell(0);
title5.setCellStyle(style);
title5.setCellValue("百公里油耗(L/100km)");
CellRangeAddress regiontitletitle5 = new CellRangeAddress(5, 5, 0, 1);
sheet.addMergedRegion(regiontitletitle5);
Cell(row_5, style, sheet, clsyqkArray);
XSSFRow row_6 = sheet.createRow(6);
row_6.setHeight((short)500);
XSSFCell title6 = row_6.createCell(0);
title6.setCellStyle(style);
title6.setCellValue("燃油费(元)");
CellRangeAddress regiontitletitle6 = new CellRangeAddress(6, 6, 0, 1);
sheet.addMergedRegion(regiontitletitle6);
Cell(row_6, style, sheet, clsyqkArray);
XSSFRow row_7 = sheet.createRow(7);
row_7.setHeight((short)500);
XSSFCell title7 = row_7.createCell(0);
title7.setCellStyle(style);
title7.setCellValue("维修保养费(元)");
CellRangeAddress regiontitletitle7 = new CellRangeAddress(7, 7, 0, 1);
sheet.addMergedRegion(regiontitletitle7);
Cell(row_7, style, sheet, clsyqkArray);
XSSFRow row_8 = sheet.createRow(8);
row_8.setHeight((short)500);
XSSFCell title8 = row_8.createCell(0);
title8.setCellStyle(style);
title8.setCellValue("路桥费(元)");
CellRangeAddress regiontitletitle8 = new CellRangeAddress(8, 8, 0, 1);
sheet.addMergedRegion(regiontitletitle8);
Cell(row_8, style, sheet, clsyqkArray);
XSSFRow row_9 = sheet.createRow(9);
row_9.setHeight((short)500);
XSSFCell title9 = row_9.createCell(0);
title9.setCellStyle(style);
title9.setCellValue("保险费(元)");
CellRangeAddress regiontitletitle9 = new CellRangeAddress(9, 9, 0, 1);
sheet.addMergedRegion(regiontitletitle9);
Cell(row_9, style, sheet, clsyqkArray);
XSSFRow row_10 = sheet.createRow(10);
row_10.setHeight((short)500);
XSSFCell title10 = row_10.createCell(0);
title10.setCellStyle(style);
title10.setCellValue("其它费用(元)");
CellRangeAddress regiontitletitle10 = new CellRangeAddress(10, 10, 0, 1);
sheet.addMergedRegion(regiontitletitle10);
Cell(row_10, style, sheet, clsyqkArray);

XSSFRow row_11 = sheet.createRow(11);
row_11.setHeight((short)500);
XSSFCell title11 = row_11.createCell(0);
title11.setCellStyle(style);
title11.setCellValue("全年里程合计(Km)");
CellRangeAddress regiontitletitle11 = new CellRangeAddress(11, 11, 0, 1);
sheet.addMergedRegion(regiontitletitle11);
XSSFCell title11_text = row_11.createCell(2);
title11_text.setCellStyle(style);
title11_text.setCellValue(qnlchj);
CellRangeAddress regiontitletitletitle11_text = new CellRangeAddress(11, 11, 2, 17);
sheet.addMergedRegion(regiontitletitletitle11_text);
XSSFRow row_12 = sheet.createRow(12);
row_12.setHeight((short)500);
XSSFCell title12 = row_12.createCell(0);
title12.setCellStyle(style);
title12.setCellValue("全年油耗量合计(L)");
CellRangeAddress regiontitletitle12 = new CellRangeAddress(12, 12, 0, 1);
sheet.addMergedRegion(regiontitletitle12);
XSSFCell title12_text = row_12.createCell(2);
title12_text.setCellStyle(style);
title12_text.setCellValue(qnjyl);
CellRangeAddress regiontitletitletitle12_text = new CellRangeAddress(12, 12, 2,9);
sheet.addMergedRegion(regiontitletitletitle12_text);
XSSFCell title12_text1 = row_12.createCell(10);
title12_text1.setCellStyle(style);
title12_text1.setCellValue("全年百公里油耗(L/100Km)");
CellRangeAddress regiontitletitletitle12_text1 = new CellRangeAddress(12, 12, 10,13);
sheet.addMergedRegion(regiontitletitletitle12_text1);
XSSFCell title12_text2 = row_12.createCell(14);
title12_text2.setCellStyle(style);
title12_text2.setCellValue(qnbglyh);
CellRangeAddress regiontitletitletitle12_text2 = new CellRangeAddress(12, 12, 14,17);
sheet.addMergedRegion(regiontitletitletitle12_text2);

XSSFRow row_13 = sheet.createRow(13);
row_13.setHeight((short)500);
XSSFCell title13 = row_13.createCell(0);
title13.setCellStyle(style);
title13.setCellValue("全年费用合计(元)");
CellRangeAddress regiontitletitle13 = new CellRangeAddress(13, 13, 0, 1);
sheet.addMergedRegion(regiontitletitle13);
XSSFCell title13_text = row_13.createCell(2);
title13_text.setCellStyle(style);
title13_text.setCellValue(ryf+wxbyf+qtfy+lqf+bxf);
CellRangeAddress regiontitletitletitle13_text = new CellRangeAddress(13, 13, 2, 17);
sheet.addMergedRegion(regiontitletitletitle13_text);
XSSFRow row_14 = sheet.createRow(14);
row_14.setHeight((short)500);
XSSFCell title14 = row_14.createCell(0);
title14.setCellStyle(style);
title14.setCellValue("分析说明");
CellRangeAddress regiontitletitle14 = new CellRangeAddress(14, 14, 0, 1);
sheet.addMergedRegion(regiontitletitle14);
XSSFCell title14_text = row_14.createCell(2);
title14_text.setCellStyle(style);
title14_text.setCellValue("");
CellRangeAddress regiontitletitletitle14_text = new CellRangeAddress(14, 14,2, 17);
sheet.addMergedRegion(regiontitletitletitle14_text);

XSSFCell cell1 = row1.createCell(2);
cell1.setCellStyle(style);
cell1.setCellValue("第一季度");

XSSFRow row2 = sheet.createRow(1);
row2.setHeight((short)500);
XSSFCell cell2 = row2.createCell(2);
cell2.setCellStyle(style);
cell2.setCellValue("1月");
XSSFCell cell3 = row2.createCell(3);
cell3.setCellStyle(style);
cell3.setCellValue("2月");
XSSFCell cell4 = row2.createCell(4);
cell4.setCellStyle(style);
cell4.setCellValue("3月");
XSSFCell cell5 = row2.createCell(5);
cell5.setCellStyle(style);
cell5.setCellValue("小计");
CellRangeAddress region = new CellRangeAddress(0, 0, 2, 5);
sheet.addMergedRegion(region);
// 第二季度
XSSFCell cell6 = row1.createCell(6);
cell6.setCellStyle(style);
cell6.setCellValue("第二季度");

XSSFCell cell7 = row2.createCell(6);
cell7.setCellStyle(style);
cell7.setCellValue("4月");
XSSFCell cell8 = row2.createCell(7);
cell8.setCellStyle(style);
cell8.setCellValue("5月");
XSSFCell cell9 = row2.createCell(8);
cell9.setCellStyle(style);
cell9.setCellValue("6月");
XSSFCell cell10 = row2.createCell(9);
cell10.setCellStyle(style);
cell10.setCellValue("小计");
CellRangeAddress region1 = new CellRangeAddress(0, 0, 6, 9);
sheet.addMergedRegion(region1);

// 第三季度
XSSFCell cell11 = row1.createCell(10);
cell11.setCellStyle(style);
cell11.setCellValue("第三季度");

XSSFCell cell12 = row2.createCell(10);
cell12.setCellStyle(style);
cell12.setCellValue("7月");
XSSFCell cell13 = row2.createCell(11);
cell13.setCellStyle(style);
cell13.setCellValue("8月");
XSSFCell cell14 = row2.createCell(12);
cell14.setCellStyle(style);
cell14.setCellValue("9月");
XSSFCell cell15 = row2.createCell(13);
cell15.setCellStyle(style);
cell15.setCellValue("小计");
CellRangeAddress region2 = new CellRangeAddress(0, 0, 10, 13);
sheet.addMergedRegion(region2);

// 第四季度
XSSFCell cell21 = row1.createCell(14);
cell21.setCellStyle(style);
cell21.setCellValue("第四季度");
XSSFCell cell22 = row2.createCell(14);
cell22.setCellStyle(style);
cell22.setCellValue("10月");
XSSFCell cell23 = row2.createCell(15);
cell23.setCellStyle(style);
cell23.setCellValue("11月");
XSSFCell cell24 = row2.createCell(16);
cell24.setCellStyle(style);
cell24.setCellValue("12月");
XSSFCell cell25 = row2.createCell(17);
cell25.setCellStyle(style);
cell25.setCellValue("小计");
CellRangeAddress region4 = new CellRangeAddress(0, 0, 14, 17);
sheet.addMergedRegion(region4);
if(wb !=null){
try
{
String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
String headStr = "attachment; filename=" + fileName + "";
response.reset();// 清空输出流
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", headStr);
OutputStream out = response.getOutputStream();
wb.write(out);
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}

Excel中复杂跨行跨列数据的更多相关文章

  1. 在excel中如何给一列数据批量加上双引号

    在实际开发中,会遇到这样的需求,大量的数据,需要从配置文件里读取,客户给到的枚举值是字符串,而配置文件里的数据,是json格式,需要加上双引号,这样就需要使用Excel来批量格式化一下数据. 客户给到 ...

  2. 在EXCEL中,判断同列数据重复,并标识出来

    推荐方法:建立辅助列,查找B列数据是否重复.=IF(COUNTIF(B:B,B1)>1,"重复","")按住公式单元格右下角实心十字,向下拖拽复制公式.= ...

  3. excel 快速比对两列数据差异

      excel 快速比对两列数据差异 CreateTime--2018年5月31日11:19:35 Author:Marydon 1.情景展示 找出两列数据的差异 2.具体操作 方式一:使用条件格式 ...

  4. 在EXCEL中如何让一列数字变成文本格式?就是想让单元格的左上角变一个绿绿的?

    如何在EXCEL中如何让一列数字变成文本格式?就是想让单元格的左上角变一个绿绿的? 解决方案:将整列单元格格式设为文本,然后,选中该列,数据--分列--完成 详细步骤: (1)选中1行或者1列,再单击 ...

  5. C# 使用Epplus导出Excel [1]:导出固定列数据

    C# 使用Epplus导出Excel [1]:导出固定列数据 C# 使用Epplus导出Excel [2]:导出动态列数据 C# 使用Epplus导出Excel [3]:合并列连续相同数据 C# 使用 ...

  6. C# 使用Epplus导出Excel [2]:导出动态列数据

    C# 使用Epplus导出Excel [1]:导出固定列数据 C# 使用Epplus导出Excel [2]:导出动态列数据 C# 使用Epplus导出Excel [3]:合并列连续相同数据 C# 使用 ...

  7. excel中快捷计算单一列中的所有的值

    excel中快捷计算单一列中的所有的值 比如B列中所有的值 =SUM(B1:B100) 计算B列第一行到第100行的值 又学了一招  如果想统计B列所有的值 可以用 =SUM(B:B)

  8. 【转载】C#通过Remove方法移除DataTable中的某一列数据

    在C#中的Datatable数据变量的操作过程中,有时候我们需要移除当前DataTable变量中的某一列的数据,此时我们就需要使用到DataTable变量内部的Columns属性变量的Remove方法 ...

  9. excel中在某一列上的所有单元格的前后增加

    excel中在某一列上的所有单元格的前后增加数字汉字字符等东西的函数这样写 “东西”&哪一列&“东西” 例如  “1111”&E1&“3333”

随机推荐

  1. 2018.07.04 POJ 3304 Segments(简单计算几何)

    Segments Time Limit: 1000MS Memory Limit: 65536K Description Given n segments in the two dimensional ...

  2. Python是什么

    Python是一种编程语言,它的名字来源于一个喜剧.也许最初设计Python这种语言的人并没有想到今天Python会在工业和科研上获得如此广泛的使用.著名的自由软件作者Eric Raymond在他的文 ...

  3. Node.js是什么[译]

    当我向人们介绍Node.js的时候,一般会有两种反应:多数立刻表示“哦,这样啊”,另外的则会感到困惑. 如果你是第二种的话,我会试着这样解释node: 这是一个命令行工具.你可以下载一个tar包,然后 ...

  4. Codeforces777D Cloud of Hashtags 2017-05-04 18:06 67人阅读 评论(0) 收藏

    D. Cloud of Hashtags time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  5. Android SQLiteOpenHelper Sqlite数据库升级onUpgrade

    Android Sqlite数据库升级,在Android APP开发之中,非常常见: 在确定原来的数据库版本号之后,在原来数据库版本号+1,就会执行onUpgrade方法,进行数据库升级操作: 在on ...

  6. Android Studio注释摸版配置

    随意创建一个类,就会自动生成注释摸版: 配置后的效果: 以下步骤是配置过程: 1.在创建类的过程中,对类进行自定义摸版,只需在 File->Settins->Editor->File ...

  7. Windows 8/8.1 及 Windows Phone 8 应用神器 - APP Producer

    继 App studio 以及  Project Siena 之后 微软再次打造应用生成器 APP Producer,这个版本的应用生成器功能相对比之前两个版本要简单许多,更适合入门并且真正的支持全平 ...

  8. CentOS搭建NFS服务

    系统结构 ----------------------------------------------------------------------------------------------- ...

  9. flume 整合kafka

    背景:系统的数据量越来越大,日志不能再简单的文件的保存,如此日志将会越来越大,也不方便查找与分析,综合考虑下使用了flume来收集日志,收集日志后向kafka传递消息,下面给出具体的配置 # The ...

  10. 曲演杂坛--Update的小测试

    今天偶然想起一个UPDATE相关的小问题,正常情况下,如果我们将UPDATE改写成与之对应的SELECT语句,其SELECT查询结果应与UPDATE的目标表存在一对一的关系,例如: 对于UPDATE语 ...