POI Excel导出样式设置
- HSSFSheet sheet = workbook.createSheet("sheetName"); //创建sheet
- sheet.setVerticallyCenter(true);
- //下面样式可作为导出左右分栏的表格模板
- sheet.setColumnWidth((short) 0, (short) 2600);// 设置列宽
- sheet.setColumnWidth((short) 1, (short) 2400);
- sheet.setColumnWidth((short) 2, (short) 2300);
- sheet.setColumnWidth((short) 3, (short) 1600);
- sheet.setColumnWidth((short) 4, (short) 1800);
- sheet.setColumnWidth((short) 5, (short) 1000);// 空列设置小一些
- sheet.setColumnWidth((short) 6, (short) 2600);// 设置列宽
- sheet.setColumnWidth((short) 7, (short) 2400);
- sheet.setColumnWidth((short) 8, (short) 2300);
- sheet.setColumnWidth((short) 9, (short) 1600);
- sheet.setColumnWidth((short) 10, (short) 1800);
- HSSFCellStyle cellstyle = (HSSFCellStyle) workbook.createCellStyle();// 设置表头样式
- cellstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 设置居中
- HSSFCellStyle headerStyle = (HSSFCellStyle) workbook .createCellStyle();// 创建标题样式
- headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); //设置垂直居中
- headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); //设置水平居中
- HSSFFont headerFont = (HSSFFont) workbook.createFont(); //创建字体样式
- headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 字体加粗
- headerFont.setFontName("Times New Roman"); //设置字体类型
- headerFont.setFontHeightInPoints((short) 8); //设置字体大小
- headerStyle.setFont(headerFont); //为标题样式设置字体样式
- HSSFCellStyle headerStyle1 = (HSSFCellStyle) workbook .createCellStyle();// 创建标题样式1
- headerStyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
- headerStyle1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
- HSSFFont headerFont1 = (HSSFFont) workbook.createFont();
- headerFont1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 字体加粗
- headerFont1.setFontName("Times New Roman");
- headerFont1.setFontHeightInPoints((short) 8);
- headerStyle1.setFont(headerFont1);
- HSSFCellStyle headerStyle2 = (HSSFCellStyle) workbook .createCellStyle();// 创建标题样式2
- headerStyle2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
- headerStyle2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
- HSSFFont headerFont2 = (HSSFFont) workbook.createFont();
- headerFont2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 字体加粗
- headerFont2.setFontName("Times New Roman");
- headerFont2.setFontHeightInPoints((short) 8);
- headerStyle2.setFont(headerFont2);
- headerStyle2.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
- headerStyle2.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
- headerStyle2.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
- headerStyle2.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
- HSSFCellStyle cell_Style = (HSSFCellStyle) workbook .createCellStyle();// 设置字体样式
- cell_Style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
- cell_Style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直对齐居中
- cell_Style.setWrapText(true); // 设置为自动换行
- HSSFFont cell_Font = (HSSFFont) workbook.createFont();
- cell_Font.setFontName("宋体");
- cell_Font.setFontHeightInPoints((short) 8);
- cell_Style.setFont(cell_Font);
- cell_Style.setBorderBottom(HSSFCellStyle.BORDER_THIN); // 下边框
- cell_Style.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框
- cell_Style.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框
- cell_Style.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框
- HSSFRow row = sheet.createRow((short)1); //创建行
- HSSFCell cell = row.createCell((short)1); //创建列
- cell.setCellStyle(headerStyle2); //单元格引用样式
POI-Excel导出样式设置.java67行Java
POI Excel导出样式设置的更多相关文章
- Asp.Net中应用Aspose.Cells输出报表到Excel 及样式设置
解决思路: 1.找个可用的Aspose.Cells(有钱还是买个正版吧,谁开发个东西也不容易): 2.在.Net方案中引用此Cells: 3.写个函数ToExcel(传递一个DataTable),可以 ...
- Excel导出时设置单元格的格式为文本
问题: 用excel导出数据时,如何设置单元格格式的数字分类为"文本",默认是"常规"? 比如:导出编码0235A089,在Excel查看默认显示的是没有前面的 ...
- java POI excel 导出复合样式(一个单元格两个字体)
前言:java poi 导出 excel 时,需要设置一个单元格有多个字体样式,有点类似于富文本. 想要达到的效果(一个单元格里): 我使用的 poi 版本是 <dependency> & ...
- poi excel导出,下载
poi.jar包 public void downExcel(HttpServletResponse response,Page<ShopApply> page) throws Excep ...
- POI excel导出
******************************* excel表格导出,使用POI实现 ******************************* 实现导出步骤 --配置导出excel ...
- poi excel导出 xssf 带下拉框
需求:导出之后带有二级级联的下拉框.(类似于省市). 最初的思路是怀疑是不是数组内串太多了,导出之后的excel有36行,调试的误区在于刚开始认为对行数有限制,后自己写了一个测试类,才发现不是行数,而 ...
- .Net的Excel 导出 格式设置
添加引用:Microsoft Excel 11.0 Object Library ; 添加:using Microsoft.Office.Interop.Excel; 一.打开Exce ...
- java poi excel导入模板设置下拉框
import org.apache.poi.hssf.usermodel.DVConstraint; import org.apache.poi.hssf.usermodel.HSSFCell; im ...
- PowerBuilder中调用NPOI进行Excel导出格式设置示例
// 功能 :新建excel带边框的单元格,格式为数字并显示为美元货币 // 参数 :ai_row,行号:ai_col,列号 // 返回值 :true/false // 作者 :潮崖之飔 // 日期 ...
随机推荐
- ios-cocos2d游戏开发基础-CCLayer和Touch事件-开发笔记
有时候在同一个场景里你需要多个CCLayer.你可以参照以下代码生成这样的场景 +(id) scene { CCScene* scene = [CCScene node]; CCLayer* back ...
- Linux likely unlikely
/************************************************************************* * Linux likely unlikely * ...
- LeetCode Letter Combinations of a Phone Number 电话号码组合
题意:给一个电话号码,要求返回所有在手机上按键的组合,组合必须由键盘上号码的下方的字母组成. 思路:尼玛,一直RE,题意都不说0和1怎么办.DP解决. class Solution { public: ...
- 【C#学习笔记】类型转换
using System; namespace ConsoleApplication { class Program { static void Main(string[] args) { " ...
- MyBatis批量删除 多态sql,构建in语句
<!--==========================删除==================================== --> <delete id=&quo ...
- Android访问权限大全
android.permission.ACCESS_CHECKIN_PROPERTIES 允许读写访问”properties”表在checkin数据库中,改值可以修改上传( Allows read/w ...
- nginx配置:location配置方法及实例详解
今天深入研究了下nginx的location的用法,已经一些需要注意的细节,现在做一个归纳总结,以备后面查询. location匹配的是nginx的哪个变量? $request_uri locatio ...
- XNA Game Studio4.0 Programming 随便读,随便记。
一.精灵和2D图形 1.什么是2D ? 2D可以理解为 two-Dimentionanl , 2-dimentional 的缩写. 意就是两维的,比如 数学中的 直角坐标系 所能描述的就是一个2D的 ...
- Activity生命周期与状态保存
弹出系统对话框,程序仍部分可见 onPause 对话框消失时 onResume 调用一个新的Activity,老的Activity不可见时 onPause->onStop 从新的Activi ...
- Maven解决Missing artifact com.sun:tools:jar:1.5.0错误
<dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> ...