写道
private void exportSelectSonProject(HttpServletRequest request,
HttpServletResponse response) throws Exception {
DoradoContext ctx = DoradoContext.getContext();
Map map = new HashMap<String, String>();
String flowProjectYear = toString(ctx.getParameter("flowProjectYear"));
String flowStateId = toString(ctx.getParameter("flowStateId"));
String flowProjectName = toString(ctx.getParameter("flowProjectName"));
String flowProjectAcceptid = toString(ctx.getParameter("flowProjectAcceptid"));
String flowProjectIndex = toString(ctx.getParameter("flowProjectIndex"));
String flowProjectSn = toString(ctx.getParameter("flowProjectSn"));
String sysOrgId = toString(ctx.getParameter("sysOrgId"));
String flowProjectTypeid = toString(ctx.getParameter("flowProjectTypeid"));
String flowProjectKindid = toString(ctx.getParameter("flowProjectKindid"));
String flowProjectSequence = toString(ctx.getParameter("flowProjectSequence"));
String flowProjectClassid = toString(ctx.getParameter("flowProjectClassid"));
String startTime = toString(ctx.getParameter("startTime"));
String endTime = toString(ctx.getParameter("endTime"));
map.put("flowProjectYear", flowProjectYear);
map.put("flowStateId", flowStateId);
map.put("flowProjectName", flowProjectName);
map.put("flowProjectAcceptid", flowProjectAcceptid);
map.put("flowProjectIndex", flowProjectIndex);
map.put("flowProjectSn", flowProjectSn);
map.put("sysOrgId", sysOrgId);
map.put("flowProjectTypeid", flowProjectTypeid);
map.put("flowProjectKindid", flowProjectKindid);
map.put("flowProjectSequence", flowProjectSequence);
map.put("flowProjectClassid", flowProjectClassid);
map.put("startTime", startTime);
map.put("endTime", endTime);
String reportName = "项目查询-IT项目预算汇总报表" + System.currentTimeMillis();
String sheetName = "IT项目预算汇总报表";
String fileName = reportName + ".xls";// 文件名
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename="
+ URLEncoder.encode(fileName, "UTF-8"));
OutputStream os = response.getOutputStream();// 输出流
CreativeExcelExport excel = new CreativeExcelExport(); // HSSFExcel对象
String[] columnName = new String[] { "项目状态", "项目名称", "项目索引", "主办部门", "项目归属",
"项目类型", "项目性质", "项目年度"};
List dataList = new ArrayList();
NewFlowProjectListAction act = (NewFlowProjectListAction) SpringBeanFactory
.getBean("flowprojectAction_new");
FlowProjectSvc svc = (FlowProjectSvc) SpringBeanFactory
.getBean("flowprojectSvc_new");
act.setFlowProjectSvc(svc);
FlowProjectMgr mgr = (FlowProjectMgr) SpringBeanFactory
.getBean("flowprojectMgr_new");
svc.setFlowProjectMgr(mgr);
FlowProjectDao dao = (FlowProjectDao) SpringBeanFactory
.getBean("flowprojectDao_new");
mgr.setFlowProjectDao(dao);
dataList = svc.getSelectFlowProjectBaseInfos(map);
excel.projectInfoDataToExcel(reportName, sheetName, os, dataList, columnName);
}
/**
* 项目统计项目信息
* 外部调用导入合并Excel接口的方法
*
* @param reportName
* 报告标题
* @param sheetName
* 页名称
* @param os
* 输出流
* @param data
* 数据
* @throws IOException
*
*/
@SuppressWarnings("unchecked")
public void projectInfoDataToExcel(String reportName, String sheetName,
OutputStream os, List data, String[] columnName) throws IOException {
Sheet sheet = this.getHSSFSheet(sheetName);
this.writeTitle(sheet, reportName, columnName.length);
this.writeColumnName(sheet, columnName);
exportProjectInfoData(sheet, data);
writeResponse(os);
}
/**
* 写文件标题
*
* @param sheet
* @param titleName
*
*/
private void writeTitle(Sheet sheet, String titleName, int columnNum) {
Row row = sheet.createRow((short) 0);
// 设定标题位置
CellStyle style = this.getWorkBook().createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setWrapText(true);
// 设置标题字体
Font font = this.getWorkBook().createFont();
font.setFontHeightInPoints((short) 10); // 字体大小
font.setFontName("Arial"); // 什么字体
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 字体加粗
style.setFont(font);
// Cell cell = null;
// for (int i = 0; i < columnNum; i++) {
// cell = row.createCell(i);
// cell.setCellStyle(style);
// if (i == 1 || i == 8 || i == 12 || i == 11 || i >= 14) {
//
// sheet.setColumnWidth(i, 10000);
// }
// if (i == 0 || i == 2 || (i >= 4 && i <= 7) || i == 9 || i == 13) {
// sheet.setColumnWidth(i, 4000);
// } else {
// sheet.setColumnWidth(i, 2500);
// }
// }
// cell.setCellValue(titleName);
// this.MergeCell(sheet, 0, 0, 0, columnNum - 1);
}
/**
* 写列名称
*
* @param sheet
* @param titleName
*
*/
private void writeColumnName(Sheet sheet, String[] columnName) {
Row row = sheet.createRow((short) 0);
// 设定列位置
CellStyle colNameStyle = this.getWorkBook().createCellStyle();
colNameStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中
colNameStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
colNameStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
colNameStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
colNameStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
colNameStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
// 设置列字体
Font font = this.getWorkBook().createFont();
font.setFontHeightInPoints((short) 14); // 字体大小
font.setFontName("Arial"); // 什么字体
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 字体加粗
colNameStyle.setFont(font);
for (int i = 0; i < columnName.length; i++) {
Cell cell = row.createCell(i);
cell.setCellValue(columnName[i]);
cell.setCellStyle(colNameStyle);
}
}
/**
*
* 负责将数据输出到Excel逻辑处理(单个报告)
* @param sheet
* @param dataList
*/
@SuppressWarnings("unchecked")
private void exportProjectInfoData(Sheet sheet, List dataList) {
if (dataList != null && dataList.size() > 0) {
for (int i = 0; i < dataList.size(); i++) {
FlowProjectBaseinfoVO data = (FlowProjectBaseinfoVO) dataList
.get(i);
int curRow = i + 1;
Row row = sheet.createRow((short) curRow);
row.setHeight((short) 600);
// 设定数据样式
CellStyle style = this.getWorkBook().createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 水平居中
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 垂直居中
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setWrapText(true);
Cell curCell0 = row.createCell(0);
if (data.getFlowProjectSn()!= null) {
curCell0.setCellValue(data.getFlowProjectSn());
}
curCell0.setCellStyle(style);
sheet.setColumnWidth(0, 8000);
Cell curCell1 = row.createCell(1);
if (data.getFlowProjectName() != null) {
curCell1.setCellValue(data.getFlowProjectName());
}
curCell1.setCellStyle(style);
sheet.setColumnWidth(1, 4000);
Cell curCell2 = row.createCell(2);
if (data.getFlowProjectTypeName()!= null) {
curCell2.setCellValue(data.getFlowProjectTypeName());
}
curCell2.setCellStyle(style);
sheet.setColumnWidth(2, 4000);
Cell curCell3 = row.createCell(3);
if (data.getFlowProjectKindName() != null) {
curCell3.setCellValue(data.getFlowProjectKindName());
}
curCell3.setCellStyle(style);
sheet.setColumnWidth(3, 4000);
Cell curCell4 = row.createCell(4);
if (data.getFlowProjectClassName() != null) {
curCell4.setCellValue(data.getFlowProjectClassName());
}
curCell4.setCellStyle(style);
sheet.setColumnWidth(4, 4000);
Cell curCell5= row.createCell(5);
if (data.getFlowProjectYear() != null) {
curCell5.setCellValue(data.getFlowProjectYear());
}
curCell5.setCellStyle(style);
sheet.setColumnWidth(5, 4000);
}
}
Row row = sheet.getRow(0);
for(int i = 0; i < 16; i++){
if(i==0){
Cell cell = row.getCell(i);
if(null != cell){
String str = cell.getStringCellValue();
int length = str.getBytes().length;
sheet.setColumnWidth((short)i,(short)(length*600));
}
}else{
Cell cell = row.getCell(i);
if(null != cell){
String str = cell.getStringCellValue();
int length = str.getBytes().length;
sheet.setColumnWidth((short)i,(short)(length*400));
}
}
}
}
分享到:
相关推荐
java导出Excel 时候 相同行合并(可合并多列); 已测试通过;
java导出excel超过65536条记录出错 java导出excel超过65536条记录出错 java导出excel超过65536条记录出错 java导出excel超过65536条记录出错
java导出excel POI jar包 java代码地址http://blog.csdn.net/awenluck/article/details/51488537
java导出excel
该工具类实现java导出树形结构的方法,并未采用excel分组功能实现,而是根据树节点显示层级设置excel样式。针对easyUi,treeGrid开发的导出excel功能。方法简便实用、性强、通俗易懂。项目中亲测,no problem。
java导出excel例子,使用的是poi,可以分sheet导出,可以导出txt
java导出excel2007的实现,含2003格式。
资源描述:一个使用java做的导出数据,并且可以在excel表生成折线图的工具类,使用简单操作方便。
本资源实现了Excel的简单导出实例,同时也实现了导出Excel复合表头的简单实例,适合一些需要用到导出Excel技术的初学者。
java导出excel方式,含POI3.10jar包,都可以正常应用到项目中。
Java导出Excel文件(97--2003) 含jar包,注释全,可直接运行。
* 导出excel(利用反射机制) * String[] title = {"订单号","商品名称","商品价格","创建时间"}; * String[] field = {"orderNum","productName","productPrice","createTime"}; * ExportTools.export("sellJoin...
java导出Excel表格,支持标题合并居中,字体修改,带表头,全部是调好的项目搭起就可以用,该项目是在三层架构中实现
该资源是一个rar压缩包形式的源代码,主要演示了java如何导出数据到Excle并保存到本地电脑、以及在web中如何导出数据库中的数据到Excel并下载。
java导出数据到excel中的相关jar包。导出Excel的技术有两种Jakarta POI和Java Excel。
java导出CVS,csv只是一种文件的形式。。。就是按照逗号(英文逗号)分隔的文件 它的做成跟普通的文件做成是一样一样的,只需要创建一个文件(*.csv),把字符串按照一定的格式(AAA,BBB\nCCC,DDD注意必须是英文的...
Java导出Excel缩小填充,网上找了好多都没找到例子说实现不了,后面不经意间看到根据模板填充数据,解决了每个单元不同的样式问题。
java导出excel
struts2导出excel java 导出excel: JXL_excel: 可以直接在elipse下运行的例子 可以直接导出excel文件(包含所需的jar包) CSharpJExcel: 是JXL的官方下载的 包括详细的文档 和jar包
java工程,源代码,可直接运行,需自己改造成web下载方式。