poi横纵导出
dao
<select id="selectTargetModel" resultMap="targetMap">
select si.SHOP_NAME shopName,si.SHOP_ID,DATE_FORMAT(t.datadate,'%m/%Y') datadate,
IFNULL(sum(t.quantity),) quantity,IFNULL(t.product_model,) model,t.class_id
from t_target t
JOIN shop_info si on si.SHOP_ID=t.target_id
<include refid="listwhere"/>
and t.class_id= and si.flag=
GROUP BY si.shop_id,t.product_model
</select> <select id="selectKeyModel" resultMap="targetMap">
select tm.branch_model model from t_modelmap tm where tm.isKey=
and tm.party_id=#{countryId}
and tm.flag=
order by tm.branch_model desc
</select>
service
//导出印尼目标
public XSSFWorkbook exportTargetExcel(@Param("searchStr")String searchStr,@Param("conditions")String conditions,String[] excelHeader,String excelHeader1,String excelHeader2,String title) throws Exception;
service.impl
@Override
public XSSFWorkbook exportTargetExcel(String searchStr, String conditions,
String[] excelHeader, String excelHeader1,String excelHeader2, String title)
throws Exception {
//查询门店以及门店整体目标
List<IndonTarget> list = indontargetDao.selectShopList(searchStr,conditions);
//分公司的所有关键机型
List<IndonTarget> ModelKeyList = indontargetDao.selectKeyModel(WebPageUtil.getLoginedUser().getPartyId()); //查询门店关键机型目标
List<IndonTarget> ModelList = indontargetDao.selectTargetModel(searchStr, conditions); // SimpleDateFormat format = new SimpleDateFormat("MM/yyyy");
// Date date =new Date();
//
// String d = format.format(date);
// System.out.println(d+"-------------9999----------------");
// Date dt = format.parse(d);
// System.out.println(d+"-------------9999----------------"); int[] excelWidth = {,,,};
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(title); //导出字体样式
XSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) ); // 字体大小 //导出样式
XSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setFont(font); //导出样式
XSSFCellStyle style1 = workbook.createCellStyle();
style1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style1.setFont(font);
// style1.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
// style1.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
// style1.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
// style1.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
style1.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); sheet.createFreezePane(,,,);//锁定参数1为起始列,参数2为起始行,3结整列,4为结束行
sheet.addMergedRegion(new CellRangeAddress(,,,));// 起始行号,终止行号, 起始列号,终止列号
sheet.addMergedRegion(new CellRangeAddress(,,,));// 起始行号,终止行号, 起始列号,终止列号
sheet.addMergedRegion(new CellRangeAddress(,,,ModelKeyList.size()+));// 起始行号,终止行号, 起始列号,终止列号 for (int i = ; i < excelWidth.length; i++) {
sheet.setColumnWidth(i, * excelWidth[i]);
} XSSFRow row = sheet.createRow(); //表头数据
for (int i = ; i < excelHeader.length; i++) {
XSSFCell cell = row.createCell(i);
cell.setCellValue(excelHeader[i]);
cell.setCellStyle(style1); } XSSFRow row1 = sheet.createRow();
XSSFCell cell1 = row1.createCell();
cell1.setCellValue(excelHeader1);
cell1.setCellStyle(style1); XSSFCell cell10 = row.createCell();
cell10.setCellValue(excelHeader2);
cell10.setCellStyle(style1); //门店整体目标 动态左边门店
for (int a = ; a < list.size(); a++) {
row = sheet.createRow(a+);
IndonTarget indTarget = list.get(a);
//获得 当前的门店ID
String shop=indTarget.getShopId()+""; if(indTarget.getShopName()!=null && indTarget.getShopName()!=""){
XSSFCell cell = row.createCell();
cell.setCellValue(indTarget.getShopName());
cell.setCellStyle(style);
} XSSFCell cell = row.createCell();
cell.setCellValue(indTarget.getDatadate());
cell.setCellStyle(style); XSSFCell cell2 = row.createCell();
cell2.setCellValue(indTarget.getQuantity());
cell2.setCellStyle(style); //所有分公司关键机型 动态头部机型
for (int i = ; i < ModelKeyList.size(); i++) {
IndonTarget keyModel = ModelKeyList.get(i);
//获得当前型号
String key=keyModel.getModel(); XSSFCell cell0 = row1.createCell(i+);
cell0.setCellValue(key);
cell0.setCellStyle(style1);
XSSFCell cell3 = row.createCell(i+);
//分公司某个关键机型目标
for (int j = ; j < ModelList.size(); j++) {
IndonTarget indTargetData = ModelList.get(j);
String thisShop=indTargetData.getShopId()+"";
if(thisShop.equals(shop) && indTargetData.getModel().equals(key) ){
cell3.setCellValue(indTargetData.getQuantity()); } }
cell3.setCellStyle(style);
} } return workbook;
}
action
public void exportTargetExcel(){
try {
String title="Indonesia TV Target";
String fileName = title+".xlsx";
final String userAgent = request.getHeader("USER-AGENT");
if(null!=userAgent){
if (- != userAgent.indexOf("Firefox")) {//Firefox
fileName = new String(fileName.getBytes(), "ISO8859-1");
}else if (- != userAgent.indexOf("Chrome")) {//Chrome
fileName = new String(fileName.getBytes(), "ISO8859-1");
} else {//IE7+
fileName = URLEncoder.encode(fileName, "UTF-8");
fileName = StringUtils.replace(fileName, "+", "%20");//替换空格
}
} else {
fileName = fileName;
}
String datadate = request.getParameter("datadate");
String shop = request.getParameter("shopName");
SimpleDateFormat dfd = new SimpleDateFormat("yyyy-MM");// 设置日期格式
Date d = new Date();
String dt = dfd.format(d);
String searchStr = "1 = 1";
if(shop!=null && !shop.equals("")){
shop=shop.replace("\'", "\\'");
searchStr += " and si.shop_name like ('%"+shop+"%')";
}
if(datadate!=null && !datadate.equals("")){
searchStr += " and date_format(t.datadate,'%Y-%m') ='"+datadate+"'";
}else{
searchStr += " and date_format(t.datadate,'%Y-%m') ='"+dt+"'";
}
//权限
String userPartyIds = WebPageUtil.loadPartyIdsByUserId();
String conditions = "";
if(!WebPageUtil.isHAdmin()){
if(null!=userPartyIds && !"".equals(userPartyIds)){
conditions +=" si.COUNTRY_ID in ("+userPartyIds+")";
}else
{
conditions += " 1=2 ";
}
}else{
conditions += " 1=1 ";
}
String[] excelHeader={
"*Shop Name","*Month","Total Target"
};
String excelHeader1=
"*Quantity"
;
String excelHeader2=
"*Model Target"
;
XSSFWorkbook workbook =indonTargetServce.exportTargetExcel(conditions,searchStr, excelHeader,excelHeader1,excelHeader2, title);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
OutputStream ouputStream = response.getOutputStream();
workbook.write(ouputStream);
ouputStream.flush();
ouputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
poi横纵导出的更多相关文章
- Java中使用poi导入、导出Excel
一.介绍 当前B/S模式已成为应用开发的主流,而在企业办公系统中,常常有客户这样子要求:你要把我们的报表直接用Excel打开(电信系统.银行系统).或者是:我们已经习惯用Excel打印.这样在我们实际 ...
- Java使用POI实现数据导出excel报表
Java使用POI实现数据导出excel报表 在上篇文章中,我们简单介绍了java读取word,excel和pdf文档内容 ,但在实际开发中,我们用到最多的是把数据库中数据导出excel报表形式.不仅 ...
- java使用poi将html导出word,默认打开页面视图
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:o ...
- POI导入和导出Excel总结
POI导入和导出Excel总结 POI使用总结 1.POI读取Excel 打开工作簿的方式有以下两种简单的应用,POI读取和输出工作簿文件都可以通过以下两种方式来声明: //通过输入流的方式打开本 ...
- apache poi根据模板导出excel
需要预先新建编辑好一个excel文件,设置好样式. 编辑好输出的数据,根据excel坐标一一对应. 支持列表数据输出,列表中列合并. 代码如下: package com.icourt.util; im ...
- 转:POI操作Excel导出
package com.rd.lh.util.excel; import java.beans.PropertyDescriptor; import java.io.FileOutputStream; ...
- 使用POI实现数据导出Excel表格
package cn.sh.bzt.kwj.action; import java.io.IOException; import java.io.OutputStream; import java.t ...
- Java POI 两种导出方式
这里面包含了模板导出方法和自定义模板进行导出 package jp.co.syspro.poo.action.hibikoyou; import java.io.ByteArrayOutputStre ...
- 一个poi操作实现导出功能的类
public class ExportExcel<T> { public void exportExcel(Collection<T> dataset, OutputStrea ...
随机推荐
- react native 环境报错
按照react native中文网的文档安装 1.brew 管理软件 2.node 在终端启动工程后就报下面这个错误 这个错误是在RN在第一次配置环境启动一个工程的时候 ,在这过程中下载的缓存文件不完 ...
- 如何使用HackRF做一个简单的IMSI捕获器
关于IMSI IMSI为国际用户识别码(International Mobile Subscriber Identity)的缩写,是用于区分蜂窝网络中不同用户的,在所在蜂窝网络中不重复的识别码.IMS ...
- 剑指Offer 4. 重建二叉树 (二叉树)
题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7, ...
- 利用教育邮箱注册JetBrains产品(pycharm、idea等)的方法
转载:http://www.cnblogs.com/wang-meng/p/8887436.html 1,申请邮箱 地址为:http://mdu.edu.rs/ 邮箱的前缀可以改成自己喜欢的字符 ...
- windows 重装系统
转载:https://blog.csdn.net/qq_41137650/article/details/80035921 老毛桃 大白菜都可以 电脑系统安装步骤我选的是用U盘做的系统 如果本计系 ...
- NAS (Network Attached Storage)
当电脑硬盘容量满了,多数使用者第一个想法就是买一块几TB的硬盘来扩充,如果是笔电的使用者,第一个想到的是买一个外接式硬盘来备份资料,这样的想法并没有错,那是当你还不知道有「NAS」这个好用的东西,才会 ...
- 1.6 selenium3+firefox环境搭建
1.6 selenium3+firefox环境搭建 有不少小伙伴在安装selenium环境后启动firefox报错,因为现在selenium升级到3.0了,跟2.0的版本还有有一点区别的.(备注:这里 ...
- 安装Vmware workstation虚拟机软件
运行下载完成的Vmware Workstation虚拟机软件包,将会看到图1-1 所示的虚拟机程序安装向导初始界面. 在虚拟机软件的安装向导界面单击"下一步"按钮,如图1-2所示. ...
- cannot find package "context"
导入 github.com/go-sql-driver/mysql 和 database/sql 时,报cannot find package "context"的错误因为go1 ...
- CentOS 7 快速部署 ELK
先简单说一下部署思路及原理(不一定正确,只是个人理解而已) 1.修改系统参数,以便安装软件 2.安装配置elasticsearch,这个相当于总监测中心,用来收集logstash监测的各种服务应用日志 ...