public static void main(String[] args) {

try {
FileOutputStream out = new FileOutputStream("d:\\excel13.xls");
HSSFWorkbook wb = new HSSFWorkbook();

Font headFont = wb.createFont();
headFont.setFontName("宋体");
headFont.setFontHeightInPoints((short) 18);// 字体大小
headFont.setBold(true);// 字体大小

CellStyle headStyle = wb.createCellStyle();
headStyle.setFont(headFont);
headStyle.setAlignment(HorizontalAlignment.CENTER);// 左右居中
headStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中

//创建sheet页
HSSFSheet sheet = wb.createSheet("农村集体监督资金支付明细");
sheet.setColumnWidth(0,4500);
sheet.setColumnWidth(1,3500);
sheet.setColumnWidth(2,3000);
sheet.setColumnWidth(3,4500);
sheet.setColumnWidth(4,3000);
sheet.setColumnWidth(5,3000);

//创建行
HSSFRow row0 = sheet.createRow(0);
row0.setHeight((short)800);
//创建单元格
HSSFCell cell00 = row0.createCell(0);
//往单元格中设置值
cell00.setCellValue("农村集体监督资金支付明细");
cell00.setCellStyle(headStyle);

//合并单元格
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

Font cellFont = wb.createFont();
cellFont.setFontName("宋体");
cellFont.setFontHeightInPoints((short) 12);// 字体大小
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFont(cellFont);
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中

CellStyle cellStyle2 = wb.createCellStyle();
cellStyle2.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中
cellStyle2.setFont(cellFont);

HSSFRow row1 = sheet.createRow(1);
row1.setHeight((short)500);
HSSFCell cell10 = row1.createCell(0);
cell10.setCellValue("申请单位");
cell10.setCellStyle(cellStyle2);

HSSFCell cell11 = row1.createCell(1);
cell11.setCellValue("");
cell11.setCellStyle(cellStyle2);

HSSFCell cell15 = row1.createCell(5);
cell15.setCellValue("");
cell15.setCellStyle(cellStyle2);

sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 4));

HSSFRow row2 = sheet.createRow(2);
row2.setHeight((short)500);

for(int i=0;i<6;i++){
HSSFCell cell = row2.createCell(i);
if(i==0){
cell.setCellValue("款项用途");
}else if(i==2){
cell.setCellValue("yiyi");
}else{
cell.setCellValue("");
}
cell.setCellStyle(cellStyle);
}

sheet.addMergedRegion(new CellRangeAddress(2, 2, 1, 5));

HSSFRow row3 = sheet.createRow(3);
row3.setHeight((short)500);

HSSFCell cell30 = row3.createCell(0);

for(int i=0;i<6;i++){
HSSFCell cell = row3.createCell(i);
if(i==0){
cell.setCellValue("金额");
}else if(i==1){
cell.setCellValue("yiyi");
}else if(i==5){
cell.setCellValue(11);
}else{
cell.setCellValue("");
}
cell.setCellStyle(cellStyle);
}

sheet.addMergedRegion(new CellRangeAddress(3, 3, 1, 4));

HSSFRow row4 = sheet.createRow(4);
row4.setHeight((short)500);

for(int i=0;i<6;i++){
HSSFCell cell = row4.createCell(i);
if(i==0){
cell.setCellValue("付款方式");
}else if(i==1){
cell.setCellValue("单笔转账支付");
}else{
cell.setCellValue("");
}
cell.setCellStyle(cellStyle);
}

sheet.addMergedRegion(new CellRangeAddress(4, 4, 1, 5));

HSSFRow row5 = sheet.createRow(5);
row5.setHeight((short)500);
for(int i=0;i<6;i++){
HSSFCell cell = row5.createCell(i);
if(i==0){
cell.setCellValue("付款人名称");
}else if(i==3){
cell.setCellValue("付款人账号");
}else{
cell.setCellValue("");
}
cell.setCellStyle(cellStyle);
}
sheet.addMergedRegion(new CellRangeAddress(5, 5, 1, 2));
sheet.addMergedRegion(new CellRangeAddress(5, 5, 4, 5));

HSSFRow row6 = sheet.createRow(6);
row6.setHeight((short)500);
for(int i=0;i<6;i++){
HSSFCell cell = row6.createCell(i);
if(i==0){
cell.setCellValue("收款人名称");
}else if(i==3){
cell.setCellValue("收款人账号");
}else{
cell.setCellValue("");
}
cell.setCellStyle(cellStyle);
}
sheet.addMergedRegion(new CellRangeAddress(6, 6, 1, 2));
sheet.addMergedRegion(new CellRangeAddress(6, 6, 4, 5));

CellStyle cellStyle3 = wb.createCellStyle();
cellStyle3.setFont(cellFont);
cellStyle3.setBorderRight(BorderStyle.THIN);
cellStyle3.setBorderBottom(BorderStyle.THIN);
cellStyle3.setBorderLeft(BorderStyle.THIN);
cellStyle3.setBorderTop(BorderStyle.THIN);
cellStyle3.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中
cellStyle3.setAlignment(HorizontalAlignment.CENTER);// 上下居中

HSSFRow row7 = sheet.createRow(7);
row7.setHeight((short)600);
for(int i=0;i<6;i++){
HSSFCell cell7 = row7.createCell(i);
if(i==0){
cell7.setCellValue("审批情况");
}else{
cell7.setCellValue("");
}
cell7.setCellStyle(cellStyle3);
}
sheet.addMergedRegion(new CellRangeAddress(7, 7, 0, 5));

CellStyle cellStyle4 = wb.createCellStyle();
cellStyle4.setFont(cellFont);
cellStyle4.setBorderRight(BorderStyle.THIN);
cellStyle4.setBorderBottom(BorderStyle.THIN);
cellStyle4.setBorderLeft(BorderStyle.THIN);
cellStyle4.setBorderTop(BorderStyle.THIN);
cellStyle4.setVerticalAlignment(VerticalAlignment.CENTER);// 上下居中
cellStyle4.setAlignment(HorizontalAlignment.CENTER);
HSSFRow row8 = sheet.createRow(8);
row8.setHeight((short)500);
for(int i=0;i<6;i++){
HSSFCell cell = row8.createCell(i);
if(i==0){
cell.setCellValue("职务");
}else if(i==1){
cell.setCellValue("审核审批状态");
}else if(i==2){
cell.setCellValue("审核审批意见");
}else if(i==3){
cell.setCellValue("");
}else if(i==4){
cell.setCellValue("审核审批人签字");
}else if(i==5){
cell.setCellValue("审核日期");
}
cell.setCellStyle(cellStyle4);
}
sheet.addMergedRegion(new CellRangeAddress(8, 8, 2, 3));

HSSFRow row9 = sheet.createRow(9);
row9.setHeight((short)500);
for(int i=0;i<6;i++){
HSSFCell cell = row9.createCell(i);
if(i==0){
cell.setCellValue("职务");
}else if(i==1){
cell.setCellValue("审核审批状态");
}else if(i==2){
cell.setCellValue("审核审批意见");
}else if(i==3){
cell.setCellValue("");
}else if(i==4){
try {
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
BufferedImage bufferImg = null;
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
bufferImg = ImageIO.read(new File("F:\\小憩\\Map.png"));
ImageIO.write(bufferImg, "png", byteArrayOut);
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 1023, 250,(short) 4, 9, (short) 4, 9);
anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG));
} catch (IOException e) {
e.printStackTrace();
}
}else if(i==5){
cell.setCellValue("审核日期");
}
cell.setCellStyle(cellStyle4);
}
sheet.addMergedRegion(new CellRangeAddress(9, 9, 2, 3));

wb.write(out);
out.close();
} catch (IOException e) {
e.printStackTrace();
}

}

导出带有图片的excel的更多相关文章

  1. java 导出blob图片到excel

    实现功能,导出当前页面显示员工的图片,核心代码已给出,仅供参考, 如需转载请注明出处http://www.cnblogs.com/wangjianguang/p/7852060.html 随便再扯2句 ...

  2. 导出包含图片的excel、word、pdf 笔记

    /** * 导出word * @throws Exception */ @Override public byte[] WordExport( List<VbLibGlobalAnalyList ...

  3. 导出带图片的Excel——OOXML文件分析

    需求: 普通js导出文件excel具有兼容性问题,通过js-xsl导出文件API未找到导出图片的方案,实例过少,因此针对07年后以.xlsx后缀的excel文件,通过修改后缀.zip参考文件模板来实现 ...

  4. C#导出带有格式的Excel(列宽,合并单元格,显示边框线,加背景颜色等)

    源地址:http://blog.sina.com.cn/s/blog_74f702e60101au55.html 导出excel相关设置:http://blog.csdn.net/wanmingtom ...

  5. eclipse导出带有图片、音效、其他二进制文件的jar文件的经历

    先说下简单流程吧: 1.选中“项目”,右键->export->java的“jar file”->勾选“export generated clas files and resource ...

  6. Java POI 导出带有图片的word

    1. 引入maven ,具体可以上github看一下,这里做简单的说明,是一个大神封装了一下 官方提供的语法 文本语法是 {{Text}} 图片语法是{{@Image}} 其他的自己去看官方文档 &l ...

  7. JAVA将Excel中的报表导出为图片格式(一)问题背景

    如题所示,先抛出一个问题,如何使用JAVA将Excel中的报表导出为图片格式? 首先说一下这个问题的背景,也就是为什么博主会碰到这个问题 随着微信,易信之流大行其道,企业内部的办公交流.绩效考评甚至考 ...

  8. OpenXml Excel数据导入导出(含图片的导入导出)

    声明:里面的很多东西是基于前人的基础上实现的,具体是哪些人 俺忘了,我做了一些整合和加工 这个项目居于openxml做Excel的导入导出,可以用OpenXml读取Excel中的图片 和OpenXml ...

  9. Laravel Excel模板导出-带图片

    Laravel Excel版本 3.1 1.数据准备 建个2个表,加点数据,控制器中查数据,给模板使用. 表1-order:id, order_no, img_path, note 表2-order_ ...

随机推荐

  1. PSO 粒子群算法

    注:本人参考http://www.cnblogs.com/tiandsp/category/348031.html来实现的 算法步骤: 1.首先确定粒子个数与迭代次数. 2.对每个粒子随机初始化位置与 ...

  2. Python利用xlutils统计excel表格数据

    假设有像上这样一个表格,里面装满了各式各样的数据,现在要利用模板对它进行统计每个销售商的一些数据的总和.模板如下: 代码开始: 1 #!usr/bin/python3 2 # -*-coding=ut ...

  3. Linux下源码安装方式安装MySQL

    1.下载安装包:https://downloads.mysql.com/archives/community/  2.安装开发工具和安装包 因为要把源码编译成二进制数据,所以必须要有编译器和解释器 g ...

  4. ASP.NET Core 3.1 IOC容器以及默认DI以及替换Autofac生命周期

    IOC 就是我们需要一个对象 以前我们是去 new 现在我们是直接向 IOC容器 要我们需要的那个对象. 使用一个IOC容器(autofac)通过依赖注入控制各个组件的耦合.也就是说你写好了组件,不需 ...

  5. 熬夜肝了这篇Spring Cloud Gateway的功能及综合使用

    前言 SpringCloud 是微服务中的翘楚,最佳的落地方案. Spring Cloud Gateway 是 Spring Cloud 新推出的网关框架,之前是 Netflix Zuul.网关通常在 ...

  6. Apache Calcite 论文学习笔记

    特别声明:本文来源于掘金,"预留"发表的[Apache Calcite 论文学习笔记](https://juejin.im/post/5d2ed6a96fb9a07eea32a6f ...

  7. Docker安装系列教程

    首先准备一台Centos7版本的虚拟机,它支持docker容器技术.本案例使用centos7虚拟机安装docker容器. 一.安装 1.启动虚拟机,配置虚拟机能够访问互联网 2. 安装支持软件包,提供 ...

  8. Oracle误删数据的恢复

    Oracle误删数据的恢复,分为两种方法:SCN和时间戳两种方法恢复. 一.通过SCN恢复删除且已提交的数据 1.获得当前数据库的SCN号 select current_scn from v$data ...

  9. 2021升级版微服务教程6—Ribbon使用+原理+整合Nacos权重+实战优化 一篇搞定

    2021升级版SpringCloud教程从入门到实战精通「H版&alibaba&链路追踪&日志&事务&锁」 教程全目录「含视频」:https://gitee.c ...

  10. 【JavaWeb】Cookie&Session

    Cookie&Session Cookie 什么是 Cookie Cookie 即饼干的意思 Cookie 是服务器通知客户端保存键值对的一种技术 客户端有了 Cookie 后,每次请求都发送 ...