supperpoi⾃定义excel标题头并导出
原⽂链接:
创建excel⼤致分这⼏步:
1、创建HSSFWorkbook对象(也就是excel⽂档对象)
2、通过HSSFWorkbook对象创建sheet对象(也就是excel中的sheet)
3、通过sheet对象创建HSSFROW对象(row⾏对象)
4、通过HSSFROW对象创建列cell并t值(列名)
controller 层
/**
* excel⾃定义导出
* @param hAqscTieupsummary
leanon* @param request
* @param respon
* @param dataGrid
* @param modelMap
* @return
*/
@SuppressWarnings("deprecation")
@RequestMapping(params = "exportEXL")
public String exportEXL(HAqscTieupsummaryEntity hAqscTieupsummary,
HttpServletRequest request, HttpServletRespon respon,
DataGrid dataGrid, ModelMap modelMap) {
try {
String dateType = "yyyy";
SimpleDateFormat df = new SimpleDateFormat(dateType);// 设置⽇期格式
SimpleDateFormat df1 = new SimpleDateFormat("yyyy.MM.dd");// 设置⽇期格式
// 创建HSSFWorkbook对象(excel的⽂档对象)
HSSFWorkbook wb = new HSSFWorkbook();
HSSFRow row = null;
HSSFCell cell = null;
// 建⽴新的sheet对象(excel的表单) 并设置sheet名字
HSSFSheet sheet = wb.createSheet("占压管线台账信息");
sheet.tDefaultRowHeightInPoints(30);// 设置缺省列⾼sheet.tDefaultColumnWidth(20);//设置缺省列宽
//----------------标题样式---------------------
HSSFCellStyle titleStyle = wb.createCellStyle(); //标题样式
titleStyle.tAlignment(HSSFCellStyle.ALIGN_CENTER);
lsp 什么意思titleStyle.tVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
Font ztFont = wb.createFont();
ztFont.tItalic(fal); // 设置字体为斜体字
ztFont.tColor(Font.COLOR_NORMAL); // 将字体设置为“红⾊”
ztFont.tFontHeightInPoints((short)16); // 将字体⼤⼩设置为18px
ztFont.tFontName("宋体"); // 将“宋体”字体应⽤到当前单元格上
ztFont.tBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //加粗
//ztFont.tUnderline(Font.U_DOUBLE); // 添加(Font.U_SINGLE单条下划线/Font.U_DOUBLE双条下划线) // ztFont.tStrikeout(true); // 是否添加删除线
titleStyle.tFont(ztFont);
//-------------------------------------------
//----------------⼆级标题格样式----------------------------------
HSSFCellStyle titleStyle2 = wb.createCellStyle(); //表格样式
ztFont2.tColor(Font.COLOR_NORMAL); // 将字体设置为“红⾊”
ztFont2.tFontHeightInPoints((short)11); // 将字体⼤⼩设置为18px
ztFont2.tFontName("宋体"); // 字体应⽤到当前单元格上
ztFont2.tBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //加粗
//ztFont.tUnderline(Font.U_DOUBLE); // 添加(Font.U_SINGLE单条下划线/Font.U_DOUBLE双条下划线) //ztFont.tStrikeout(true); // 是否添加删除线
titleStyle2.tFont(ztFont2);
//----------------------------------------------------------
//----------------单元格样式----------------------------------
HSSFCellStyle cellStyle = wb.createCellStyle(); //表格样式
cellStyle.tAlignment(HSSFCellStyle.ALIGN_CENTER);
cellStyle.tVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
cellStyle.tBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
cellStyle.tBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
cellStyle.tBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
cellStyle.tBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
Font cellFont = wb.createFont();
cellFont.tItalic(fal); // 设置字体为斜体字
cellFont.tColor(Font.COLOR_NORMAL); // 将字体设置为“红⾊”
cellFont.tFontHeightInPoints((short)10); // 将字体⼤⼩设置为18px
cellFont.tFontName("宋体"); // 字体应⽤到当前单元格上
//cellFont.tBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
cellStyle.tFont(cellFont);
cellStyle.tWrapText(true);//设置⾃动换⾏
//----------------------------------------------------------
// ----------------------创建第⼀⾏---------------
// 在sheet⾥创建第⼀⾏,参数为⾏索引(excel的⾏),可以是0~65535之间的任何⼀个
row = ateRow(0);
// 创建单元格(excel的单元格,参数为列索引,可以是0~255之间的任何⼀个
cell = ateCell(0);
/
/ 合并单元格CellRangeAddress构造参数依次表⽰起始⾏,截⾄⾏,起始列, 截⾄列
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 19));
// 设置单元格内容
加班费英文
cell.tCellValue("占压城市地下管线、输油⽓管道、化⼯产品管道违法违规建设汇总表");
cell.tCellStyle(titleStyle);
// ----------------------------------------------
// ------------------创建第⼆⾏(单位、填表⽇期)---------------------
row = ateRow(1); // 创建第⼆⾏
汉语言文学就业cell = ateCell(0);
cell.tCellValue("填报单位名称(盖章): ");
cell.tCellStyle(titleStyle2);
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 3));
cell = ateCell(4);
sheet.addMergedRegion(new CellRangeAddress(1, 1, 4, 5));
TSBaUr tb = SessionUrName(); //获取当前登录⽤户信息
String uid = tb.getId();
String deptId = DeptId(uid);
String deptName = DeptName(deptId);
cell.tCellValue(deptName);
//cell.tCellValue("*****");
//HSSFCell cell14 = ateCell(15); // 填表时间
//cell14.tCellValue();
/
/cell14.tCellValue("2017.11.30");
// cell14.tCellStyle(titleStyle2);
// ----------------------------------------------
// ------------------创建表头start---------------------
row = ateRow(2); // 创建第三⾏
sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
cell = ateCell(0);
cell.tCellValue("序号");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 1, 1));
cell = ateCell(1);
cell.tCellValue("隐患等级评定");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 2, 2));
cell = ateCell(2);
cell.tCellValue("隐患名称");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 2, 3, 5));
cell = ateCell(3);
cell.tCellValue("位置描述");
cell.tCellStyle(cellStyle);
cell = ateCell(4);
cell.tCellStyle(cellStyle);
cell = ateCell(5);
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 2, 6, 10)); cell = ateCell(6);
cell.tCellValue("管线情况");
cell.tCellStyle(cellStyle);
cell = ateCell(7);
cell.tCellStyle(cellStyle);
cell = ateCell(8);
cell.tCellStyle(cellStyle);
cell = ateCell(9);
cell.tCellStyle(cellStyle);
乐匙音乐教育
cell = ateCell(10);
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 2, 11, 13)); cell = ateCell(11);
cell.tCellValue("占压物情况");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 2, 14, 14)); cell = ateCell(14);
cell.tCellValue("占压物⽤途");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 15, 15)); cell = ateCell(15);
cell.tCellValue("已采⽤的安全防护措施");
layerthr
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 16, 16)); cell = ateCell(16);
cell.tCellValue("备注");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 17, 17)); cell = ateCell(17);
cell.tCellValue("联系⼈电话");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 18, 18)); cell = ateCell(18);
cell.tCellValue("是否已和区管委和供热办联系");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 19, 19)); cell = ateCell(19);
cell.tCellValue("是否采取防范措施");
cell.tCellStyle(cellStyle);
//--------------------------- 创建第四⾏--------------------
row = ateRow(3);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 3, 3));
cell = ateCell(3);
cell.tCellValue("所在区县");
cell.tCellStyle(cellStyle);
cell = ateCell(0);
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 4, 4));
cell = ateCell(4);
cell.tCellValue("所在街道");
code是什么意思cell.tCellStyle(cellStyle);
cell = ateCell(1);
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 6, 6));
cell = ateCell(6);
cell.tCellValue("管线建成时间");
cell.tCellStyle(cellStyle);
pda是什么
sheet.addMergedRegion(new CellRangeAddress(3, 3, 7, 7));
cell = ateCell(7);
cell.tCellValue("管线埋深");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 8, 8));
cell = ateCell(8);
cell.tCellValue("管径");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 9, 9));
cell = ateCell(9);
cell.tCellValue("管线压⼒等级");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 10, 10)); cell = ateCell(10);
cell.tCellValue("占压管线长度");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 11, 11)); cell = ateCell(11);
cell.tCellValue("占压单位(个⼈)名称");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 12, 12)); cell = ateCell(12);
cell.tCellValue("占压物建成时间");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 13, 13)); cell = ateCell(13);
cell.tCellValue("占压物⾯积(平⽅⽶)");
cell.tCellStyle(cellStyle);
sheet.addMergedRegion(new CellRangeAddress(3, 3, 14, 14)); cell = ateCell(14);
cell.tCellValue("经营、出租、⾃⽤、居住");
cell.tCellStyle(cellStyle);
cell = ateCell(15);
张生云cell.tCellStyle(cellStyle);
cell = ateCell(16);
cell.tCellStyle(cellStyle);
cell = ateCell(17);