- 浏览: 135552 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
i523853827:
楼主你好,文章里面有错误,希望楼主能改正 验证的xml 是类名 ...
struts校验框架学习总结 -
renjy1123:
希望楼主分享下,我现在也要用,也不知如何着手,纠结!
OSB学习 -
fengweiyou:
说的非常好,如果不说还真不知道是哪里的问题呢。谢谢你
struts2.1.8+spring2.5.6+hibernate3.2框架搭建错误 -
2001430:
...
There is no Action mapped for action name XX.的解决 -
chilongxph:
楼上正解,此种方式的问题正在与此,如果过多的话,就只能去使用存 ...
oracle 列转行
private void writeBackupSoftExcel(OutputStream os,
TreeMap<String, ArrayList<String>> result,
ArrayList<Record> staffList) {
FileInputStream tp_in = null;
HSSFWorkbook workBook = null;
HSSFRow row = null;
HSSFCell cell = null;
// ArrayList al=new ArrayList();
// set red color style
workBook = new HSSFWorkbook();
// 创建样式一
HSSFCellStyle cs1 = workBook.createCellStyle();
HSSFFont font1 = workBook.createFont();
font1.setFontName("Arial");// 设置字体
font1.setFontHeightInPoints((short) 17);// 字体大小
font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体字体
cs1.setFont(font1);
cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平居中
cs1.setBorderBottom(HSSFCellStyle.BORDER_THIN);// 下边框
cs1.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
cs1.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
cs1.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cs1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
cs1.setWrapText(false);
// 创建样式二
HSSFCellStyle cs2 = workBook.createCellStyle();
HSSFFont font2 = workBook.createFont();
font2.setFontName("Arial");// 设置字体
font2.setFontHeightInPoints((short) 10);// 字体大小
font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);// 正常字体
cs2.setFont(font2);
cs2.setAlignment(HSSFCellStyle.ALIGN_LEFT);// 居左对齐
cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN);// 下边框
cs2.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
cs2.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
cs2.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
// cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cs2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
cs2.setWrapText(false);
//设置单个sheet的列数
int colnum=Constants.COL_NUM;
//System.out.println("--------------创建多个sheet---------");
try {
// set the sheet name
for (int m = 0; m <= staffList.size() / colnum; m++) {
// HSSFSheet sheet1 = workBook.getSheetAt(0);
HSSFSheet sheet1 = workBook.createSheet();
sheet1.setColumnWidth((short) 0, (short) (36 * 360));
workBook.setSheetName(m, "Soft Info "+m);
row = sheet1.getRow(0);
//合并A到G列
sheet1.addMergedRegion(new Region(0, (short) 0, 0, (short) 6));
if (row == null)
row = sheet1.createRow(0);
// 设置行高
row.setHeight((short) 600);
// 设置标题名
cell = row.createCell((short) 0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellStyle(cs1);
cell.setCellValue("Detail Soft Info");
// sheet1.mergeCells( 0 , 0 , 5 , 0 );
row = sheet1.getRow(1);
if (row == null)
row = sheet1.createRow(1);
// HSSFCellStyle cs3 = workBook.createCellStyle();
// //设置行背景色
// cs3.setFillBackgroundColor(new
// HSSFColor.GREY_25_PERCENT().getIndex());
// cs3.setFillForegroundColor(HSSFColor.AQUA.index);
if (staffList.size() > (m + 1) * colnum) {
for (int i = m * colnum; i < (m + 1) * colnum; i++) {
int n = i % colnum + 1;
//设置列宽
sheet1.setColumnWidth((short)n,(short)(28*200));
// //自动调整列宽
// sheet1.autoSizeColumn((short)n);
cell = row.getCell((short) n);
// cell = row.createCell((short) 0);
// cell.setCellValue("SoftWare");
if (cell == null)
cell = row.createCell((short) n);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellStyle(cs2);
boolean isPubServer = staffList.get(i).getString(
"staffno").equals(
staffList.get(i).getString("staffname"));
if (!isPubServer) {
cell.setCellValue(staffList.get(i).getString(
"staffname")
+ "("
+ staffList.get(i).getString("staffno")
+ ")");
} else {
cell.setCellValue(staffList.get(i).getString(
"staffname")
+ "[Pub Server]");
}
}
} else {
for (int i = m * colnum; i < staffList.size(); i++) {
cell = row.getCell((short) (i + 1));
int n = i % colnum + 1;
if (cell == null)
cell = row.createCell((short) n);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellStyle(cs2);
//设置列宽
sheet1.setColumnWidth((short)n,(short)(28*200));
boolean isPubServer = staffList.get(i).getString(
"staffno").equals(
staffList.get(i).getString("staffname"));
if (!isPubServer)
cell.setCellValue(staffList.get(i).getString(
"staffname")
+ "("
+ staffList.get(i).getString("staffno")
+ ")");
else
cell.setCellValue(staffList.get(i).getString(
"staffname")
+ "[Pub Server]");
}
}
// write the result
String key;
String soft_name;
String staff_id;
String vaild;
Iterator<String> it = result.keySet().iterator();
ArrayList<String> staffIDList;
for (int i = 0; i < result.size(); i++) {
key = it.next();
vaild = key.substring(0, 1);
soft_name = key.substring(1);
// start from 3st row
row = sheet1.getRow(i + 2);
if (row == null) {
row = sheet1.createRow(i + 2);
}
// write first field for soft name
cell = row.getCell((short) 0);
if (cell == null) {
cell = row.createCell((short) 0);
}
// create a font style
HSSFCellStyle style = workBook.createCellStyle();
HSSFFont redFont = workBook.createFont();
redFont.setColor(HSSFFont.COLOR_RED);
HSSFFont blackFont = workBook.createFont();
blackFont.setColor(HSSFFont.COLOR_NORMAL);
// judge illegal soft
if (vaild.equals("0")) {
style.setFont(redFont);
cell.setCellStyle(style);
}
cell.setCellValue(soft_name);
// write "*"
if ((m + 1) * colnum < staffList.size()) {
staffIDList = result.get(key);
// 获取staffId
for (int j = 0; j < staffIDList.size(); j++) {
staff_id = staffIDList.get(j);
for (int k = m * colnum; k < (m + 1) * colnum; k++) {
if (staff_id.equals(staffList.get(k).getString(
"staff_id"))) {
int n = k % colnum + 1;
cell = row.getCell((short) (n));
if (cell == null)
cell = row.createCell((short) (n));
cell.setCellValue("*");
break;
}
}
}
} else {
staffIDList = result.get(key);
for (int j = 0; j < staffIDList.size(); j++) {
staff_id = staffIDList.get(j);
for (int k = m * colnum; k < staffList.size(); k++) {
if (staff_id.equals(staffList.get(k).getString(
"staff_id"))) {
int n = k % colnum + 1;
cell = row.getCell((short) n);
if (cell == null)
cell = row.createCell((short) n);
cell.setCellValue("*");
break;
}
}
}
}
}
}
workBook.write(os);
// workBook.write(os);
} catch (Exception e) {
e.printStackTrace();
setErrorMsg("Write excel backup file error!");
log.error(getErrorMsg() + e);
throw new BizException(e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (tp_in != null) {
try {
tp_in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
使用这种方式可以有效的避免使用模板所带来的性能问题和jvm内存不足的问题,可是具体怎么做到对样式的灵活控制,我还没有搞的太明白,如有大侠路过,还请不吝赐教。
TreeMap<String, ArrayList<String>> result,
ArrayList<Record> staffList) {
FileInputStream tp_in = null;
HSSFWorkbook workBook = null;
HSSFRow row = null;
HSSFCell cell = null;
// ArrayList al=new ArrayList();
// set red color style
workBook = new HSSFWorkbook();
// 创建样式一
HSSFCellStyle cs1 = workBook.createCellStyle();
HSSFFont font1 = workBook.createFont();
font1.setFontName("Arial");// 设置字体
font1.setFontHeightInPoints((short) 17);// 字体大小
font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 粗体字体
cs1.setFont(font1);
cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平居中
cs1.setBorderBottom(HSSFCellStyle.BORDER_THIN);// 下边框
cs1.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
cs1.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
cs1.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cs1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
cs1.setWrapText(false);
// 创建样式二
HSSFCellStyle cs2 = workBook.createCellStyle();
HSSFFont font2 = workBook.createFont();
font2.setFontName("Arial");// 设置字体
font2.setFontHeightInPoints((short) 10);// 字体大小
font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);// 正常字体
cs2.setFont(font2);
cs2.setAlignment(HSSFCellStyle.ALIGN_LEFT);// 居左对齐
cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN);// 下边框
cs2.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
cs2.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
cs2.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
// cs1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cs2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
cs2.setWrapText(false);
//设置单个sheet的列数
int colnum=Constants.COL_NUM;
//System.out.println("--------------创建多个sheet---------");
try {
// set the sheet name
for (int m = 0; m <= staffList.size() / colnum; m++) {
// HSSFSheet sheet1 = workBook.getSheetAt(0);
HSSFSheet sheet1 = workBook.createSheet();
sheet1.setColumnWidth((short) 0, (short) (36 * 360));
workBook.setSheetName(m, "Soft Info "+m);
row = sheet1.getRow(0);
//合并A到G列
sheet1.addMergedRegion(new Region(0, (short) 0, 0, (short) 6));
if (row == null)
row = sheet1.createRow(0);
// 设置行高
row.setHeight((short) 600);
// 设置标题名
cell = row.createCell((short) 0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellStyle(cs1);
cell.setCellValue("Detail Soft Info");
// sheet1.mergeCells( 0 , 0 , 5 , 0 );
row = sheet1.getRow(1);
if (row == null)
row = sheet1.createRow(1);
// HSSFCellStyle cs3 = workBook.createCellStyle();
// //设置行背景色
// cs3.setFillBackgroundColor(new
// HSSFColor.GREY_25_PERCENT().getIndex());
// cs3.setFillForegroundColor(HSSFColor.AQUA.index);
if (staffList.size() > (m + 1) * colnum) {
for (int i = m * colnum; i < (m + 1) * colnum; i++) {
int n = i % colnum + 1;
//设置列宽
sheet1.setColumnWidth((short)n,(short)(28*200));
// //自动调整列宽
// sheet1.autoSizeColumn((short)n);
cell = row.getCell((short) n);
// cell = row.createCell((short) 0);
// cell.setCellValue("SoftWare");
if (cell == null)
cell = row.createCell((short) n);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellStyle(cs2);
boolean isPubServer = staffList.get(i).getString(
"staffno").equals(
staffList.get(i).getString("staffname"));
if (!isPubServer) {
cell.setCellValue(staffList.get(i).getString(
"staffname")
+ "("
+ staffList.get(i).getString("staffno")
+ ")");
} else {
cell.setCellValue(staffList.get(i).getString(
"staffname")
+ "[Pub Server]");
}
}
} else {
for (int i = m * colnum; i < staffList.size(); i++) {
cell = row.getCell((short) (i + 1));
int n = i % colnum + 1;
if (cell == null)
cell = row.createCell((short) n);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellStyle(cs2);
//设置列宽
sheet1.setColumnWidth((short)n,(short)(28*200));
boolean isPubServer = staffList.get(i).getString(
"staffno").equals(
staffList.get(i).getString("staffname"));
if (!isPubServer)
cell.setCellValue(staffList.get(i).getString(
"staffname")
+ "("
+ staffList.get(i).getString("staffno")
+ ")");
else
cell.setCellValue(staffList.get(i).getString(
"staffname")
+ "[Pub Server]");
}
}
// write the result
String key;
String soft_name;
String staff_id;
String vaild;
Iterator<String> it = result.keySet().iterator();
ArrayList<String> staffIDList;
for (int i = 0; i < result.size(); i++) {
key = it.next();
vaild = key.substring(0, 1);
soft_name = key.substring(1);
// start from 3st row
row = sheet1.getRow(i + 2);
if (row == null) {
row = sheet1.createRow(i + 2);
}
// write first field for soft name
cell = row.getCell((short) 0);
if (cell == null) {
cell = row.createCell((short) 0);
}
// create a font style
HSSFCellStyle style = workBook.createCellStyle();
HSSFFont redFont = workBook.createFont();
redFont.setColor(HSSFFont.COLOR_RED);
HSSFFont blackFont = workBook.createFont();
blackFont.setColor(HSSFFont.COLOR_NORMAL);
// judge illegal soft
if (vaild.equals("0")) {
style.setFont(redFont);
cell.setCellStyle(style);
}
cell.setCellValue(soft_name);
// write "*"
if ((m + 1) * colnum < staffList.size()) {
staffIDList = result.get(key);
// 获取staffId
for (int j = 0; j < staffIDList.size(); j++) {
staff_id = staffIDList.get(j);
for (int k = m * colnum; k < (m + 1) * colnum; k++) {
if (staff_id.equals(staffList.get(k).getString(
"staff_id"))) {
int n = k % colnum + 1;
cell = row.getCell((short) (n));
if (cell == null)
cell = row.createCell((short) (n));
cell.setCellValue("*");
break;
}
}
}
} else {
staffIDList = result.get(key);
for (int j = 0; j < staffIDList.size(); j++) {
staff_id = staffIDList.get(j);
for (int k = m * colnum; k < staffList.size(); k++) {
if (staff_id.equals(staffList.get(k).getString(
"staff_id"))) {
int n = k % colnum + 1;
cell = row.getCell((short) n);
if (cell == null)
cell = row.createCell((short) n);
cell.setCellValue("*");
break;
}
}
}
}
}
}
workBook.write(os);
// workBook.write(os);
} catch (Exception e) {
e.printStackTrace();
setErrorMsg("Write excel backup file error!");
log.error(getErrorMsg() + e);
throw new BizException(e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (tp_in != null) {
try {
tp_in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
使用这种方式可以有效的避免使用模板所带来的性能问题和jvm内存不足的问题,可是具体怎么做到对样式的灵活控制,我还没有搞的太明白,如有大侠路过,还请不吝赐教。
发表评论
-
SVN插件问题
2013-12-25 15:42 711将MyEclipse换成了eclipse,安装SVN插件后,却 ... -
Eclipse中project项目转web项目
2013-12-25 15:34 6838项目被搭建成了project项目,感觉很别扭,所以,手动进行了 ... -
sftp同步远程服务器文件
2010-10-15 14:25 3240public class SftpTool { privat ... -
使用dom4j操作xml文档
2009-12-01 13:57 11291. 获取文档对象: public static Docume ... -
dom4j
2009-09-29 01:39 1149package xml.dom4j.wkjava; impor ... -
LDAP学习手册节选
2009-09-04 17:52 5179一. ... -
单点登录
2009-08-12 17:49 1153摘要:单点登录(SSO)的技术被越来越广泛地运用到各个领域的软 ... -
js打包
2009-08-04 09:21 2562项目中需要对javascript进行打包和压缩,我选用了yu ... -
利用filter实现MVC应用框架 及 网页编码问题的解决方案
2009-04-28 00:19 1249利用filter实现MVC应用框架 及 网页编码问题的解决方案 ... -
动态代理类
2008-11-27 19:51 993动态代理类 Java动态代理类位于Java.lang.re ... -
ffmpeg转换参数和对几种视频格式的转换分析
2008-11-19 13:33 1480日志源地址:http://j2ee.blog.sohu.c ... -
网页在线播放器代码大全
2008-11-19 11:47 1454网页在线播放器代码大全 1.avi格式 <objec ... -
Java将视频转换为flash
2008-11-19 11:43 1669Java将视频转换为flash 为这个问题头痛了好久,今天看 ... -
java实现断点续传
2008-11-17 18:54 1060断点续传的原理 其实断点续传的原理很简单,就是在Http的请 ... -
java环境变量设置方法完全版
2008-11-12 10:34 2193Java编程首要工作就是安 ... -
java工作者常用网站
2008-09-20 23:38 1165[b]www.iteye.com[/b] [align=cen ...
相关推荐
java使用POI导出 Excel+图片工具类 ,里面含有poi jar包,只调用接口即可直接保存Excel。使用的时候需先把数据封装,具体包装需根据实际导出数据进行处理。文件demo中只提供包装格式。
java的poi的导入工具类,只需要传入两个arrayList,一个是execl的标题,一个是ececl的数据,就可以直接导出到execl里面,支持最新的execl,全新封装的,让每一个人都会使用poi导出execl!
使用apach poi 导出Excel,可直接在项目中使用使用apach poi 导出Excel,可直接在项目中使用使用apach poi 导出Excel,可直接在项目中使用
可以运行的POI导出Excel文件实例,里面有两种方法,一个是Servlet,一个是main
在java web系统应用中我们经常会用到大批量数据的导出,动辄就上几十万几百万的数据让我们的程序感觉...java中使用poi导出Excel大批量数据到客户端 存在两个导出方法:存在一个分批量导出ZIP文件,一个导出exel文件
Poi导出Excel工具类 支持大数据量 多sheet页方式 已经封装好,直接拿来调用里面的方法传入参数就行 很简单
一个POI导出Excel万级数据分页实现 解决内存溢出问题 完整的 project demo 有数据库dmp文件
使用poi方式导出excel,支持将多个工作簿合成一个Excel进行导出
poi导出excel demo,poi导出excel demo,poi导出excel demo,poi导出excel demo,poi导出excel demo,
java,poi方式解析导出excel需要使用的三个jar包。
POI导出Excel工具类,自动设置标题 列名 文件名,可插入图片,合并单元格
poi作为导出excel常用的工具,方便快捷。对于excel指定下拉列表的列,如何生成呢?本文提供如何生成下拉列表的excel列
该实例集成maven开发环境,里面讲解了POI导入和导出Excel表格的基本用法
struts2中利用poi导出excel的简单例子
poi 导出EXCEL 例子 poi 导出EXCEL 例子poi 导出EXCEL 例子poi 导出EXCEL 例子
poi导出excel文档
这个是java用poi操作Excel进行导出,并且可以自动换行
springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式Excel模板,完整项目,导出即用。springboot+poi导出指定格式...
使用poi导出excel支持xls、xlsx格式大数据导出java工具类,支持同一个单元格不同文本格式。找了好久,加上自己修改后,调试通过,发布出来分享,(调整student类位置)包含所需jar包,工具类,使用示例