SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
Date date = new Date();
String year = sdf.format(date);
getRequest().setCharacterEncoding("UTF-8");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0,year+"年仪器设备期间核查计划表", (short) 1);
HSSFFont font = wb.createFont();
font.setFontName("楷体");
font.setFontHeight((short) 220);
// =====过期状态
HSSFCellStyle cs2 = wb.createCellStyle();
HSSFFont font2 = wb.createFont();
font2.setFontName("宋体");
font2.setFontHeightInPoints((short) 11); //字体大小
cs2.setFont(font2);
cs2.setAlignment(HSSFCellStyle.ALIGN_CENTER);//水平居中
cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN);//下边框
cs2.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
cs2.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
cs2.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
cs2.setFillForegroundColor(HSSFColor.RED.index);//设置背景色
cs2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//标题样式
HSSFRow rowheader = sheet.createRow(0);
HSSFCell cellheader = rowheader.createCell((short) 0);
cellheader.setEncoding(HSSFCell.ENCODING_UTF_16);
HSSFCellStyle cellstyleheader = wb.createCellStyle();//样式
HSSFFont font1 = wb.createFont();
font1.setFontName("宋体");
font1.setFontHeightInPoints((short) 18);//字体大小
font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //加粗
cellstyleheader.setFont(font1);
cellstyleheader.setAlignment(HSSFCellStyle.ALIGN_CENTER);//指定单元格居中对齐
cellstyleheader.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//指定单元格垂直居中对齐
cellstyleheader.setWrapText(true);//指定单元格自动换行
cellstyleheader.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellstyleheader.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellstyleheader.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellstyleheader.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellstyleheader.setFont(font1);
cellheader.setCellStyle(cellstyleheader);
cellheader = rowheader.createCell((short) 0);
cellheader.setEncoding(HSSFCell.ENCODING_UTF_16);
cellheader.setCellValue(year+"年仪器设备期间核查计划表");
cellheader.setCellStyle(cellstyleheader);
sheet.addMergedRegion(new Region(0,(short) 0, 1,(short) 8));
//记录表示样式
HSSFRow rowheaders = sheet.createRow(2);
HSSFCell cellheaders = rowheaders.createCell((short) 0);
cellheaders.setEncoding(HSSFCell.ENCODING_UTF_16);
HSSFCellStyle cellstyleheaders = wb.createCellStyle();//样式
HSSFFont font1s = wb.createFont();
font1s.setFontName("宋体");
font1s.setFontHeightInPoints((short) 10);//字体大小
font1s.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
cellstyleheaders.setFont(font1s);
cellstyleheaders.setAlignment(HSSFCellStyle.ALIGN_LEFT);//指定单元格居右对齐
cellstyleheaders.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//指定单元格居中对齐
cellstyleheaders.setWrapText(true); //指定单元格自动换行
cellstyleheaders.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellstyleheaders.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellstyleheaders.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellstyleheaders.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellstyleheaders.setFont(font1s);
cellheaders.setCellStyle(cellstyleheaders);
cellheaders = rowheaders.createCell((short) 0);
cellheaders.setEncoding(HSSFCell.ENCODING_UTF_16);
cellheaders.setCellValue("记录标识:CHJ-CX-25-03-01");
cellheaders.setCellStyle(cellstyleheaders);
sheet.addMergedRegion(new Region(2, (short) 0,2, (short) 8));//合并单元格
sheet.setColumnWidth((short) 0, (short) 7000);
//表头样式
HSSFCellStyle titlestyle = wb.createCellStyle();//样式
HSSFFont titlesfont = wb.createFont();
titlesfont.setFontName("宋体");// 设置字体
titlesfont.setFontHeightInPoints((short) 10);// 字体大小
titlesfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗
titlestyle.setFont(titlesfont);
titlestyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 指定单元格居中对齐
titlestyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 指定单元格垂直居中对齐
titlestyle.setWrapText(true); // 指定单元格自动换行
titlestyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
titlestyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
titlestyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
titlestyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
// 表列 样式
HSSFRow row = sheet.createRow(3);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
HSSFCellStyle cellstyle = wb.createCellStyle();// 样式
HSSFFont fonttable = wb.createFont();
fonttable.setFontHeightInPoints((short) 10);// 字体大小
cellstyle.setAlignment(HSSFCellStyle.ALIGN_LEFT); // 指定单元格居中对齐
cellstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 指定单元格垂直居中对齐
cellstyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);// 水平对齐居中
cellstyle.setWrapText(true); // 指定单元格自动换行
cellstyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
cellstyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
cellstyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
cellstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
cellstyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
// cellstyle.setBorderBottom((short) 1);
cellstyle.setFont(fonttable);
cell.setCellStyle(cellstyle);
cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("序号");
cell.setCellStyle(titlestyle);
sheet.setColumnWidth((short) 0, (short) 2000);
cell = row.createCell((short) 1);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("仪器名称");
cell.setCellStyle(titlestyle);
sheet.setColumnWidth((short) 1, (short) 5000);
cell = row.createCell((short) 2);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("仪器型号");
cell.setCellStyle(titlestyle);
sheet.setColumnWidth((short) 2, (short) 4000);
cell = row.createCell((short) 3);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("仪器编号");
cell.setCellStyle(titlestyle);
sheet.setColumnWidth((short) 3, (short) 4000);
cell = row.createCell((short) 4);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("使用部门");
cell.setCellStyle(titlestyle);
sheet.setColumnWidth((short) 4, (short) 5000);
cell = row.createCell((short) 5);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("最近检定时间");
cell.setCellStyle(titlestyle);
sheet.setColumnWidth((short) 5, (short) 4000);
cell = row.createCell((short) 6);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("计划核查时间");// cell.setCellValue("测量范围");
cell.setCellStyle(titlestyle);
sheet.setColumnWidth((short) 6, (short) 4000);
cell = row.createCell((short) 7);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("核查人");
cell.setCellStyle(titlestyle);
sheet.setColumnWidth((short) 7, (short) 4000);
cell = row.createCell((short) 8);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue("备注");
cell.setCellStyle(titlestyle);
sheet.setColumnWidth((short) 8, (short) 4000);
List