POI中可能会用到一些需要设置EXCEL单元格格式的操作小结
2016-05-20 11:43
639 查看
POI中可能会用到一些需要设置EXCEL单元格格式的操作小结: 先获取工作薄对象: HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); HSSFCellStyle setBorder = wb.createCellStyle(); 一、设置背景色: setBorder.setFillForegroundColor((short) 13);// 设置背景色 setBorder.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); 二、设置边框: setBorder.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框 setBorder.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框 setBorder.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框 setBorder.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框 三、设置居中: setBorder.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 四、设置字体: HSSFFont font = wb.createFont(); font.setFontName("黑体"); font.setFontHeightInPoints((short) 16);//设置字体大小 HSSFFont font2 = wb.createFont(); font2.setFontName("仿宋_GB2312"); font2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示 font2.setFontHeightInPoints((short) 12); setBorder.setFont(font);//选择需要用到的字体格式 五、设置列宽: sheet.setColumnWidth(0, 3766); //第一个参数代表列id(从0开始),第2个参数代表宽度值 参考 :"2012-08-10"的宽度为2500 六、设置自动换行: setBorder.setWrapText(true);//设置自动换行 七、合并单元格: Region region1 = new Region(0, (short) 0, 0, (short) 6); //参数1:行号 参数2:起始列号 参数3:行号 参数4:终止列号 或者用 CellRangeAddress region1 = new CellRangeAddress(rowNumber, rowNumber, (short) 0, (short) 11); 但应注意两个构造方法的参数不是一样的,具体使用哪个取决于POI的不同版本。 sheet.addMergedRegion(region1); 目前用过的就这么多,后续有新的会继续添加。
相关文章推荐
- ThinkPHP中Common/common.php文件常用函数功能分析
- 欢迎使用CSDN-markdown编辑器
- C#多线程那点事——信号量(Semaphore)
- MySQL 和 PostgreSQL 对比
- crontab初级入门
- 解决placeholder不兼容问题
- 指令选择器调查(4)
- iOS多点连接的使用、协议逆向、安全性
- 技术服务迭代发展,码盟开创新模式
- Android数据存储之Sqlite采用SQLCipher数据库加密实战
- 参数集合拼接公共方法
- 贪婪深度神经网络概述
- Leetcode #14 in cpp
- CoordinatorLayout、AppBarLayout、TableLayout、CollapsingToolbarLayout、NestedScrollView的使用
- GDAL写矢量图
- 不管你以后写不写JS,都应该学会这种思考方式
- 数据库索引
- 微信打印实现过程和免费下载
- excel自定义函数添加和使用方法
- 文件上传之multer