- 浏览: 149904 次
- 性别:
- 来自: 五指山
文章分类
最新评论
-
dengdonglin888:
qq_30221445 写道你好 请问这种数据能解吗 < ...
Simple XML -
qq_30221445:
你好 请问这种数据能解吗 <request> ...
Simple XML -
画个逗号给明天qu:
画个逗号给明天qu 写道
Android上传文件到服务器 -
画个逗号给明天qu:
...
Android上传文件到服务器 -
alranger:
我在jsp页面加上这一段代码后,问题还是存在。
解决Ext在ie9报错:不支持extjs对象的“createContextualFragment属性或方法”
转自:http://zmx.iteye.com/blog/622536
关于POI的介绍请google一下!
- public ActionResult excelPrint() {
- HSSFWorkbook workbook = new HSSFWorkbook();// 创建一个Excel文件
- HSSFSheet sheet = workbook.createSheet();// 创建一个Excel的Sheet
- sheet.createFreezePane(1, 3);// 冻结
- // 设置列宽
- sheet.setColumnWidth(0, 1000);
- sheet.setColumnWidth(1, 3500);
- sheet.setColumnWidth(2, 3500);
- sheet.setColumnWidth(3, 6500);
- sheet.setColumnWidth(4, 6500);
- sheet.setColumnWidth(5, 6500);
- sheet.setColumnWidth(6, 6500);
- sheet.setColumnWidth(7, 2500);
- // Sheet样式
- HSSFCellStyle sheetStyle = workbook.createCellStyle();
- // 背景色的设定
- sheetStyle.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
- // 前景色的设定
- sheetStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
- // 填充模式
- sheetStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
- // 设置列的样式
- for (int i = 0; i <= 14; i++) {
- sheet.setDefaultColumnStyle((short) i, sheetStyle);
- }
- // 设置字体
- HSSFFont headfont = workbook.createFont();
- headfont.setFontName("黑体");
- headfont.setFontHeightInPoints((short) 22);// 字体大小
- headfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗
- // 另一个样式
- HSSFCellStyle headstyle = workbook.createCellStyle();
- headstyle.setFont(headfont);
- headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
- headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
- headstyle.setLocked(true);
- headstyle.setWrapText(true);// 自动换行
- // 另一个字体样式
- HSSFFont columnHeadFont = workbook.createFont();
- columnHeadFont.setFontName("宋体");
- columnHeadFont.setFontHeightInPoints((short) 10);
- columnHeadFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
- // 列头的样式
- HSSFCellStyle columnHeadStyle = workbook.createCellStyle();
- columnHeadStyle.setFont(columnHeadFont);
- columnHeadStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
- columnHeadStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
- columnHeadStyle.setLocked(true);
- columnHeadStyle.setWrapText(true);
- columnHeadStyle.setLeftBorderColor(HSSFColor.BLACK.index);// 左边框的颜色
- columnHeadStyle.setBorderLeft((short) 1);// 边框的大小
- columnHeadStyle.setRightBorderColor(HSSFColor.BLACK.index);// 右边框的颜色
- columnHeadStyle.setBorderRight((short) 1);// 边框的大小
- columnHeadStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 设置单元格的边框为粗体
- columnHeadStyle.setBottomBorderColor(HSSFColor.BLACK.index); // 设置单元格的边框颜色
- // 设置单元格的背景颜色(单元格的样式会覆盖列或行的样式)
- columnHeadStyle.setFillForegroundColor(HSSFColor.WHITE.index);
- HSSFFont font = workbook.createFont();
- font.setFontName("宋体");
- font.setFontHeightInPoints((short) 10);
- // 普通单元格样式
- HSSFCellStyle style = workbook.createCellStyle();
- style.setFont(font);
- style.setAlignment(HSSFCellStyle.ALIGN_LEFT);// 左右居中
- style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);// 上下居中
- style.setWrapText(true);
- style.setLeftBorderColor(HSSFColor.BLACK.index);
- style.setBorderLeft((short) 1);
- style.setRightBorderColor(HSSFColor.BLACK.index);
- style.setBorderRight((short) 1);
- style.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 设置单元格的边框为粗体
- style.setBottomBorderColor(HSSFColor.BLACK.index); // 设置单元格的边框颜色.
- style.setFillForegroundColor(HSSFColor.WHITE.index);// 设置单元格的背景颜色.
- // 另一个样式
- HSSFCellStyle centerstyle = workbook.createCellStyle();
- centerstyle.setFont(font);
- centerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
- centerstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
- centerstyle.setWrapText(true);
- centerstyle.setLeftBorderColor(HSSFColor.BLACK.index);
- centerstyle.setBorderLeft((short) 1);
- centerstyle.setRightBorderColor(HSSFColor.BLACK.index);
- centerstyle.setBorderRight((short) 1);
- centerstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 设置单元格的边框为粗体
- centerstyle.setBottomBorderColor(HSSFColor.BLACK.index); // 设置单元格的边框颜色.
- centerstyle.setFillForegroundColor(HSSFColor.WHITE.index);// 设置单元格的背景颜色.
- try {
- // 创建第一行
- HSSFRow row0 = sheet.createRow(0);
- // 设置行高
- row0.setHeight((short) 900);
- // 创建第一列
- HSSFCell cell0 = row0.createCell(0);
- cell0.setCellValue(new HSSFRichTextString("中非发展基金投资项目调度会工作落实情况对照表"));
- cell0.setCellStyle(headstyle);
- /**
- * 合并单元格
- * 第一个参数:第一个单元格的行数(从0开始)
- * 第二个参数:第二个单元格的行数(从0开始)
- * 第三个参数:第一个单元格的列数(从0开始)
- * 第四个参数:第二个单元格的列数(从0开始)
- */
- CellRangeAddress range = new CellRangeAddress(0, 0, 0, 7);
- sheet.addMergedRegion(range);
- // 创建第二行
- HSSFRow row1 = sheet.createRow(1);
- HSSFCell cell1 = row1.createCell(0);
- cell1.setCellValue(new HSSFRichTextString("本次会议时间:2009年8月31日 前次会议时间:2009年8月24日"));
- cell1.setCellStyle(centerstyle);
- // 合并单元格
- range = new CellRangeAddress(1, 2, 0, 7);
- sheet.addMergedRegion(range);
- // 第三行
- HSSFRow row2 = sheet.createRow(3);
- row2.setHeight((short) 750);
- HSSFCell cell = row2.createCell(0);
- cell.setCellValue(new HSSFRichTextString("责任者"));
- cell.setCellStyle(columnHeadStyle);
- cell = row2.createCell(1);
- cell.setCellValue(new HSSFRichTextString("成熟度排序"));
- cell.setCellStyle(columnHeadStyle);
- cell = row2.createCell(2);
- cell.setCellValue(new HSSFRichTextString("事项"));
- cell.setCellStyle(columnHeadStyle);
- cell = row2.createCell(3);
- cell.setCellValue(new HSSFRichTextString("前次会议要求\n/新项目的项目概要"));
- cell.setCellStyle(columnHeadStyle);
- cell = row2.createCell(4);
- cell.setCellValue(new HSSFRichTextString("上周工作进展"));
- cell.setCellStyle(columnHeadStyle);
- cell = row2.createCell(5);
- cell.setCellValue(new HSSFRichTextString("本周工作计划"));
- cell.setCellStyle(columnHeadStyle);
- cell = row2.createCell(6);
- cell.setCellValue(new HSSFRichTextString("问题和建议"));
- cell.setCellStyle(columnHeadStyle);
- cell = row2.createCell(7);
- cell.setCellValue(new HSSFRichTextString("备 注"));
- cell.setCellStyle(columnHeadStyle);
- // 访问数据库,得到数据集
- List<DeitelVO> deitelVOList = getEntityManager().queryDeitelVOList();
- int m = 4;
- int k = 4;
- for (int i = 0; i < deitelVOList.size(); i++) {
- DeitelVO vo = deitelVOList.get(i);
- String dname = vo.getDname();
- List<Workinfo> workList = vo.getWorkInfoList();
- HSSFRow row = sheet.createRow(m);
- cell = row.createCell(0);
- cell.setCellValue(new HSSFRichTextString(dname));
- cell.setCellStyle(centerstyle);
- // 合并单元格
- range = new CellRangeAddress(m, m + workList.size() - 1, 0, 0);
- sheet.addMergedRegion(range);
- m = m + workList.size();
- for (int j = 0; j < workList.size(); j++) {
- Workinfo w = workList.get(j);
- // 遍历数据集创建Excel的行
- row = sheet.getRow(k + j);
- if (null == row) {
- row = sheet.createRow(k + j);
- }
- cell = row.createCell(1);
- cell.setCellValue(w.getWnumber());
- cell.setCellStyle(centerstyle);
- cell = row.createCell(2);
- cell.setCellValue(new HSSFRichTextString(w.getWitem()));
- cell.setCellStyle(style);
- cell = row.createCell(3);
- cell.setCellValue(new HSSFRichTextString(w.getWmeting()));
- cell.setCellStyle(style);
- cell = row.createCell(4);
- cell.setCellValue(new HSSFRichTextString(w.getWbweek()));
- cell.setCellStyle(style);
- cell = row.createCell(5);
- cell.setCellValue(new HSSFRichTextString(w.getWtweek()));
- cell.setCellStyle(style);
- cell = row.createCell(6);
- cell.setCellValue(new HSSFRichTextString(w.getWproblem()));
- cell.setCellStyle(style);
- cell = row.createCell(7);
- cell.setCellValue(new HSSFRichTextString(w.getWremark()));
- cell.setCellStyle(style);
- }
- k = k + workList.size();
- }
- // 列尾
- int footRownumber = sheet.getLastRowNum();
- HSSFRow footRow = sheet.createRow(footRownumber + 1);
- HSSFCell footRowcell = footRow.createCell(0);
- footRowcell.setCellValue(new HSSFRichTextString(" 审 定:XXX 审 核:XXX 汇 总:XX"));
- footRowcell.setCellStyle(centerstyle);
- range = new CellRangeAddress(footRownumber + 1, footRownumber + 1, 0, 7);
- sheet.addMergedRegion(range);
- HttpServletResponse response = getResponse();
- HttpServletRequest request = getRequest();
- String filename = "未命名.xls";//设置下载时客户端Excel的名称
- // 请见:http://zmx.iteye.com/blog/622529
- filename = Util.encodeFilename(filename, request);
- 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();
- }
- return null;
- }
发表评论
-
tesseract-ocr识别中文扫描图片
2013-06-26 16:58 1558http://code.google.com/p/tesse ... -
java获取图片每个像素点的RGB
2013-06-26 16:46 2331http://tinyking.blog.51cto.com/ ... -
Java读取图片EXIF信息
2013-06-26 16:44 543http://hhhk.iteye.com/blog/109 ... -
Java之美[从菜鸟到高手演变]之设计模式
2012-12-10 10:12 734http://blog.csdn.net/zhangerqin ... -
GMT时间对应的解析式
2012-06-21 14:59 673ddd MMM dd HH:mm:ss K yyyy &qu ... -
简易excel读取开发包
2012-06-06 23:29 626http://fastexcel.sourceforge.ne ... -
关于java按字节截取带有汉字的字符串的解法
2012-05-09 23:43 815转自:http://lanxia39.iteye.com/bl ... -
Java线程之线程同步
2012-05-09 23:37 565转自:http://blog.csdn.net/mq612 ... -
JAVA修饰符类型(public,protected,private,friendly)的通易解释
2012-05-07 18:51 674JAVA修饰符类型(public,protected,pr ... -
Simple XML
2011-12-02 16:26 3347之前曾写过一blog : XStream序列化JAVA对象为X ... -
POI
2011-11-30 17:15 627转自:http://zmx.iteye.com/blog/62 ... -
使用poi读写excel文件
2011-11-30 14:31 643http://cangzhitao.com/java/poi- ... -
JAVA集合类
2011-11-28 22:10 671list:arraylist,vector,linkedlis ... -
java集合类总结
2011-11-28 09:53 657对象的集合 如果程序的对象数量有限,且寿命可知,那么这个程序是 ... -
[JAVA]Excel 文档操作 .
2011-11-25 11:27 768转自:http://blog.csdn.net/s ...
相关推荐
poi 使用说明和例子文档 word和pdf
就是一些简单的说明和实例展示,反正免费嘛,大家不下白不下。
使用java Apache poi 根据word模板生成word报表 仅支持docx格式的word文件,大概是word2010及以后版本,doc格式不支持。 使用说明:https://blog.csdn.net/u012775558/article/details/79678701
导出 EXCEL 的一种方式,里面有方法的功能说明
POI报表,poi案例,例子,EXAMPLE,说明文档,帮助文档。
其中包含了poi的jar包(3.0)及一个说明文档(doc格式)还有一个简单的实例
poi报表+详细文档内含实例,有详细说明
HSSF提供给用户使用的对象在rg.apache.poi.hssf.usermodel包中,主要部分包括Excel对象,样式和格式,还有辅助操作。有以下几种对象: HSSFWorkbook excel的文档对象 HSSFSheet excel的表单 HSSFRow ...
本篇面向对象为POI的初学者,含详细的Excel报表样式说明及使用附带例子.
POI实现104w条记录写入EXCEL,在这里我给出了一个成功运行的例子,也有对应的博客操作说明。
内含源码和文档说明 示例1将演示如何利用jakarta poi api 创建excel 文档。 示例2将演示如何读取excel文档中的数据。假定在d盘jtest目录下有一个文件名为gongye.xls的excel文件。
此处从获得poi数组开始说明。 创建四叉树coordinateQuadTree来建立poi的四叉树索引。 创建过程较为费时,建议另开线程。创建四叉树完成后,计算当前mapView下需要显示的annotation。 ```objc dispatch_async...
此为将Fusionchart图片与相应数据同时导出到Excel文件里。 并含有相应的jar包,及说明方法。很详细
Excel文件Web上传和解析 例子 --- - 支持xls、xlsx - 框架:Spring Boot - 解析Excel:poi-ooxml 打包: ```bash ./gradlew build ``` ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的...
java源码文件格式 : Apache POI 是 Apache 软件基金会的开源代码库,POI 提供了 Java 程序操作 Office 格式文件的功能。...笔记通过简单实例说明 POI 和 EasyExcel 的使用方法,该仓库为相关代码。
使用POI解析WORD和Excel文件 使用Jacob解析WORD文件 Google的Search API的使用 安装:直接在Eclipse中选取“import->Existing Project” Eclipse工程/ch9:原书第十二章的工程文件 使用正则表达式解析网页文件 ...
使用POI解析WORD和Excel文件 使用Jacob解析WORD文件 Google的Search API的使用 安装:直接在Eclipse中选取“import->Existing Project” Eclipse工程/ch9:原书第十二章的工程文件 使用正则表达式解析网页文件 ...
使用POI解析WORD和Excel文件 使用Jacob解析WORD文件 Google的Search API的使用 安装:直接在Eclipse中选取“import->Existing Project” Eclipse工程/ch9:原书第十二章的工程文件 使用正则表达式解析网页文件 ...
PoiService 项目的执行/测试必须执行以下说明: 环境准备: 使用默认设置(database=postgres,user=postgres, pass=123)安装 Postgres 数据库( ); 安装 TomCat 6 ( ); 安装 Maven 3.2.5 ( )。 启动服务: 在 ...
bingExcel 处理excel与java model之间转换,想做成一个excel的orm类型的框架具体使用说明可以参照 , ,当然wiki写的比较简单,大家可以fork下源码,里面有很多单元测试的例子。环境说明基于java1.7,依赖poi3.1X.jar...