jxl 创建excel
public static void performanceExcel(String sCurrPath,List<Record> list, String begin,String end) throws Exception{
SimpleDateFormat sdf = new SimpleDateFormat(("yyyy-MM-dd HH:mm:ss"));
try {
//** **********创建工作簿************ *//*
WritableWorkbook workbook = Workbook.createWorkbook(new File(sCurrPath));
//** **********创建工作表************ *//*
WritableSheet sheet = workbook.createSheet("test", 0);
//** **********设置页眉、页脚***************** *//*
sheet.setHeader("页眉", "", "第 &P 页,共 &N 页"); // 设置页眉
sheet.setFooter("", "", "&D &T"); // 设置页脚
//** ****注:以上这些&P、&D等参数可以从EXCEL的宏录制取得******* *//*
//** *********设置列宽**************** *//*
sheet.setColumnView(0, 25); // 第1列
sheet.setColumnView(1, 20);// 第2列
sheet.setColumnView(2, 20);// 第3列
sheet.setColumnView(3, 20);// 第4列
sheet.setColumnView(4, 25); // 第5列
sheet.setColumnView(5, 15); // 第6列
sheet.setColumnView(6, 15); // 第7列
sheet.setColumnView(7, 15); // 第8列
sheet.setColumnView(8, 20);
sheet.setColumnView(9, 20);
sheet.setColumnView(10, 20);
sheet.setColumnView(11, 20); sheet.setColumnView(12, 20);
sheet.setColumnView(13, 20);
sheet.setColumnView(14, 20);
sheet.setColumnView(15, 20);
sheet.setColumnView(16, 20);
sheet.setColumnView(17, 20);
sheet.setColumnView(18, 20);
sheet.setColumnView(19, 20);
sheet.setColumnView(20, 20);
sheet.getSettings().setVerticalFreeze(2);//冻结前两行
// sheet.getSettings().setHorizontalFreeze(2);//冻结前两列 //** ************设置单元格字体************** *//*
WritableFont NormalFont = new WritableFont(WritableFont.ARIAL, 10);
WritableFont BoldFont12 = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD);//加粗12号字体
WritableFont BoldFont20 = new WritableFont(WritableFont.ARIAL, 20, WritableFont.BOLD);////加粗18号字体 //** ************以下设置几种格式的单元格************ *//*
//用于台头
WritableCellFormat wcf_heading = new WritableCellFormat(BoldFont20);
wcf_heading.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
wcf_heading.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
wcf_heading.setAlignment(Alignment.CENTRE); // 水平对齐
wcf_heading.setWrap(false); // 是否换行
wcf_heading.setBackground(Colour.GRAY_25); // 用于标题
WritableCellFormat wcf_title = new WritableCellFormat(BoldFont12);
wcf_title.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
wcf_title.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
wcf_title.setAlignment(Alignment.CENTRE); // 水平对齐
wcf_title.setWrap(false); // 是否换行 // 用于跨行
WritableCellFormat wcf_merge = new WritableCellFormat(NormalFont);
wcf_merge.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
wcf_merge.setVerticalAlignment(VerticalAlignment.TOP); // 垂直对齐
wcf_merge.setAlignment(Alignment.LEFT);
wcf_merge.setWrap(true); // 是否换行
// 用于正文
NumberFormat nf = new jxl.write.NumberFormat("0.00"); //设定带小数点数字格式
WritableCellFormat wcfN = new jxl.write.WritableCellFormat(NormalFont, nf);//设定带小数数字单元格格式
wcfN.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
wcfN.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
wcfN.setAlignment(Alignment.CENTRE); // 水平对齐
wcf_merge.setWrap(false); // 是否换行
//** ************单元格格式设置完成****************** *//*
// 用于正文
WritableCellFormat wcf_text = new WritableCellFormat(NormalFont);
wcf_text.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
wcf_text.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
wcf_text.setAlignment(Alignment.CENTRE); // 水平对齐
wcf_text.setWrap(true); // 是否换行
//** ***************以下是内容************************** *//*
WritableFont wcf_font=(WritableFont) wcf_text.getFont();
WritableCellFormat wcf_numberfomart = new WritableCellFormat(wcf_font,NumberFormats.TEXT);//设置数字格式类型按照文本格式输出
wcf_numberfomart.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
wcf_numberfomart.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
wcf_numberfomart.setAlignment(Alignment.LEFT); // 水平对齐
wcf_numberfomart.setWrap(true); // 是否换行
//** ***************以下是标题************************** *//*
sheet.setRowView(0, 800); // 设置行高
sheet.setRowView(1, 1600); // 设置行高
sheet.addCell(new Label(0, 0, "业绩销售报表", wcf_heading));
sheet.mergeCells(0, 0, 20, 0); sheet.addCell(new Label(0, 1, "业务员", wcf_title));
sheet.addCell(new Label(1, 1, "所属部门", wcf_title));
sheet.addCell(new Label(2, 1, "预算收入合计", wcf_title));
sheet.addCell(new Label(3, 1, "预算支出合计", wcf_title));//支出
sheet.addCell(new Label(4, 1, "预算利润合计", wcf_title));//收入
sheet.addCell(new Label(5, 1, "实际收入合计", wcf_title));
sheet.addCell(new Label(6, 1, "手续费合计", wcf_title));
sheet.addCell(new Label(7, 1, "实际支出合计", wcf_title));
sheet.addCell(new Label(8, 1, "实际利润合计", wcf_title));
sheet.addCell(new Label(9, 1, "退款利润合计", wcf_title));
sheet.addCell(new Label(10, 1, "总利润合计", wcf_title)); sheet.addCell(new Label(11,1,"团名称",wcf_title));
sheet.addCell(new Label(12,1,"团号",wcf_title));
sheet.addCell(new Label(13,1,"目的地",wcf_title));
sheet.addCell(new Label(14,1,"类型",wcf_title));
sheet.addCell(new Label(15,1,"渠道",wcf_title));
sheet.addCell(new Label(16,1,"结算时间",wcf_title));
sheet.addCell(new Label(17,1,"实际收入",wcf_title));
sheet.addCell(new Label(18,1,"手续费",wcf_title));
sheet.addCell(new Label(19,1,"实际支出",wcf_title));
sheet.addCell(new Label(20,1,"利润",wcf_title)); int currRow = 2;
Map<String,String> map= CrmSystem.commonMap("workflowMap");
if (list != null && list.size() > 0) {
for (Record cr : list) {
String createuser = cr.get("createuser").toString();
String creatname = "";
if(StrKit.notBlank(createuser)){
CrmUser user = CrmUser.dao.findById(createuser);
creatname = user.getNickname();
}
System.out.println("creatname:"+creatname);
String depart = cr.get("depart_id").toString();
String departname = "";
if(StrKit.notBlank(depart)){
CrmDepartment department = CrmDepartment.dao.findById(depart);
departname = department.getDepartmentName();
}
List<CrmTeam> teamList = CrmTeam.getTeamList(begin, end, createuser);
int num = 1;
if(teamList != null){
if(teamList.size() >1){
num = teamList.size();
}else{
num = 0;
}
}else {
num = 0;
}
//合并行
sheet.mergeCells(0, currRow, 0, num + currRow-1);
sheet.mergeCells(1, currRow, 1, num + currRow-1);
sheet.mergeCells(2, currRow, 2, num+currRow-1);
sheet.mergeCells(3, currRow, 3, num+currRow-1);
sheet.mergeCells(4, currRow, 4, num+currRow-1);
sheet.mergeCells(5, currRow, 5, num+currRow-1);
sheet.mergeCells(6, currRow, 6, num+currRow-1);
sheet.mergeCells(7, currRow, 7, num+currRow-1);
sheet.mergeCells(8, currRow, 8, num+currRow-1);
sheet.mergeCells(9, currRow, 9, num+currRow-1);
sheet.mergeCells(10, currRow, 10, num + currRow-1);
if(teamList != null && teamList.size() >0 ){
for (CrmTeam team:teamList) {
sheet.setRowView(currRow, 400); // 设置行高 sheet.addCell(new Label(0, currRow, checkBlank(creatname), wcf_text)); sheet.addCell(new Label(1, currRow, checkBlank(departname), wcf_text));
Double yushou = Double.valueOf(cr.get("yushou").toString()); sheet.addCell(new Label(2, currRow, checkBlank(yushou), wcf_text));
Double yufu = Double.valueOf(cr.get("yufu").toString()); sheet.addCell(new Label(3,currRow,checkBlank(yufu),wcf_text));
Double bugetprofit = HelpUtil.sub(yushou, yufu); sheet.addCell(new Label(4,currRow,checkBlank(bugetprofit),wcf_text));
Double shishou = Double.valueOf(cr.get("shishou").toString()); sheet.addCell(new Label(5, currRow, checkBlank(shishou), wcf_text));
Double shouxufei = Double.valueOf(cr.get("shouxufei").toString()); sheet.addCell(new Label(6,currRow,checkBlank(shouxufei),wcf_text));
Double shifu = Double.valueOf(cr.get("shifu").toString()); sheet.addCell(new Label(7, currRow, checkBlank(shifu), wcf_text));
Double profit = HelpUtil.sub(HelpUtil.sub(shishou, shouxufei), shifu); sheet.addCell(new Label(8, currRow, checkBlank(profit), wcf_text));
Double tuizhi = Double.valueOf(cr.get("tuizhi").toString());
Double tuishou = Double.valueOf(cr.get("tuishou").toString());
Double refundProfit = HelpUtil.sub(tuizhi, tuishou); sheet.addCell(new Label(9, currRow, checkBlank(refundProfit), wcf_text));
Double totalprofit = HelpUtil.add(profit,refundProfit); sheet.addCell(new Label(10, currRow, checkBlank(totalprofit), wcf_text)); sheet.addCell(new Label(11,currRow,checkBlank(team.getTeamname()),wcf_text));
sheet.addCell(new Label(12,currRow,checkBlank(team.getTeamcode()),wcf_text));
sheet.addCell(new Label(13,currRow,checkBlank(team.getDestination()),wcf_text));
sheet.addCell(new Label(14,currRow,checkBlank(CrmTeam.teamtypeMap.get(team.getTeamtype().toString())),wcf_text));
sheet.addCell(new Label(15,currRow,checkBlank(CrmTeam.channelMap.get(team.getChannel().toString())),wcf_text));
sheet.addCell(new Label(16, currRow, checkBlank(DateUtil.dateToString(team.getSettletime(),"yyyy-MM-dd HH:mm:ss")), wcf_text));
Double comin = CrmCash.dao.getComein(Integer.valueOf(team.get("id").toString()));
sheet.addCell(new Label(17, currRow, checkBlank(comin), wcf_text));
Double fee = CrmCash.dao.getFeeprice(Integer.valueOf(team.get("id").toString()));
sheet.addCell(new Label(18,currRow,checkBlank(fee),wcf_text));
Double pay = CrmCash.dao.getPayment1(Integer.valueOf(team.get("id").toString()));
sheet.addCell(new Label(19,currRow,checkBlank(pay),wcf_text));
Double mporfit = HelpUtil.sub(HelpUtil.sub(comin, fee), pay);
sheet.addCell(new Label(20,currRow,checkBlank(mporfit),wcf_text));
currRow++;
}
} }
}
/** **********以上所写的内容都是写在缓存中的,下一句将缓存的内容写到文件中******** */
workbook.write();
/** *********关闭文件************* */
workbook.close();
} catch (RowsExceededException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
String sCurrPath = System.getProperty("java.io.tmpdir") + "\\xlsx"+ (new java.util.Date().getTime())+".xls";
jxl 创建excel的更多相关文章
- Jxl创建Excel文件和解析Excel文件
import java.io.File; import jxl.Workbook; import jxl.write.Label; import jxl.write.WritableSheet; im ...
- android开发使用jxl创建Excel
这周水了几天,今天把博客赶上,找找状态. 周五的时候终于完成了课堂测试第二阶段,主要的难点就是生成Excel表并将填写的数据插入到Excel表中. 一.jxl使用 1.创建或读取一个工作薄 Workb ...
- JXL操作Excel
jxl是一个韩国人写的java操作excel的工具, 在开源世界中,有两套比较有影响的API可 供使用,一个是POI,一个是jExcelAPI.其中功能相对POI比较弱一点.但jExcelAPI对中文 ...
- jxl导出Excel文件
一.java项目实现读取Excel文件和导出Excel文件 实现读取和导出Excel文件的代码: package servlet; import java.io.FileInputStream; im ...
- jxl读写excel的方法
jxl 只有excel基本的操作,代码操作比较方便,一般使用jxl就够了,对图片支持较好 poi功能比jxl强大但是比较吃内存,支持计算公式 具体参考链接 http://www.cnblogs. ...
- jxl读写excel, poi读写excel,word, 读取Excel数据到MySQL
这篇blog是介绍: 1. java中的poi技术读取Excel数据,然后保存到MySQL数据中. 2. jxl读写excel 你也可以在 : java的poi技术读取和导入Excel了解到写入Exc ...
- jxl创Excel档java示例代码说明
记得下载 并 导入jxl.jar 包,免积分下载地址:http://download.csdn.net/detail/u010011052/7561041 package Test; import j ...
- Java 使用 Jxl 实现 Excel 导入导出
开发过程中经常需要用到数据的导入导出功能,之前用的是POI,这次使用JXL,JXL相对于POI来说要轻量简洁许多,在数据量不大的情况下还是非常实用的.这里做一下使用JXL的学习记录.首先需要导入相应的 ...
- JXL导出Excel(只支持xls版本)——(一)
注意: 导出的后缀是xls可以直接打开,如果导出的后缀是xlsx打开报错,需要手动将名字改为xls才可以打开.也就是JXL不可以导出xlsx的excel. Jar包
随机推荐
- SQL的三种连接方式内连接、左连接、外连接
1.内连接 select * from table_a x inner join table_b y on x.a_id = y.b_id 返回两个表关键字x.a_id = y.b_id的交集数据集 ...
- iOS TTF文件改变字体
TTF(True Type Font):是一种字库名称 TTF文件:是Apple公司和Microsoft公司共同推出的字体文件格式 使用: 1 获取字体文件 从各种渠道下载字体ttf,网站或从别的ip ...
- pig和mysql脚本对比
测试数据位于:/home/hadoop/luogankun/workspace/sync_data/pig dept和emp表来源自oracle数据库自带的表 dept.txt ACCOUNTING ...
- css3网站收集
把群里大家推荐的网站做了下收集,等有时间了研究下 1.http://icomoon.io/app/ 这个网站用来生成跟导出字体图标的,自带的图标种类很多很丰富,基本够用了,不过你也可以自己设计,然后 ...
- leetcode91
class Solution { public int numDecodings(String s) { if(s.length()==0){ return 0; } int[] dp = new i ...
- PHP依赖注入
对于依赖注入 我现在的理解是把一个方法当成一个变量放进另一个方法的形参里 <?php class Factory { public static function getDb(){ return ...
- js实现点击按钮弹出上传文件的窗口
转自:https://www.jb51.net/article/100916.htm 1.详细描述 在页面上设置一个“选择文件”按钮,点击该按钮,会弹出本地磁盘信息用于选择文件. 2.代码 ? 1 2 ...
- shiro与threamleaf的整合
1.添加依赖 2.在配置类中添加shiroDialect
- delphi ios grid BindSourceDB bug
BindSourceDB4.DataSet :=nil; BindSourceDB4.DataSet :=FDMemTable1; grid绑定后显示数据正常,第二次赋值BindSourceDB4.D ...
- 使用示例带你提前了解 Java 9 中的新特性
使用示例带你提前了解 Java 9 中的新特性 转载来源:https://juejin.im/post/58c5e402128fe100603cc194 英文出处:https://www.journa ...