| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- package restcontroller.webmanage.sale.competitor;
- import org.apache.poi.ss.usermodel.BorderStyle;
- import org.apache.poi.ss.util.CellRangeAddress;
- import org.apache.poi.xssf.usermodel.*;
- public class CompetitorExcel {
- /**
- * 2022-07-14 17:41:39
- * 设置表格宽度(导入模板)
- **/
- public static void setBatchDetailSheetColumn1(XSSFSheet sheet) {
- sheet.setDefaultRowHeight((short) 600);
- short width = 2000;
- sheet.setColumnWidth((short) 0, width * 3);
- sheet.setColumnWidth((short) 1, width * 3);
- sheet.setColumnWidth((short) 2, width * 2);
- sheet.setColumnWidth((short) 3, width * 5);
- sheet.setColumnWidth((short) 4, width * 5);
- }
- /**
- * 2022-07-14 17:41:39
- * 设置表格宽度(返回错误Excel的样式)
- **/
- public static void setBatchDetailSheetColumn2(XSSFSheet sheet) {
- sheet.setDefaultRowHeight((short) 600);
- short width = 2000;
- sheet.setColumnWidth((short) 0, width * 3);
- sheet.setColumnWidth((short) 1, width * 3);
- sheet.setColumnWidth((short) 2, width * 2);
- sheet.setColumnWidth((short) 3, width * 5);
- sheet.setColumnWidth((short) 4, width * 5);
- sheet.setColumnWidth((short) 5, width * 5);
- }
- /**
- * 2022-07-14 17:42:03
- * 设置表头
- * cellStyle1 中文提示信息样式
- * cellStyle2 标题提示信息样式
- * cellStyle3 正文提示信息样式
- **/
- public static void batchDetail(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFCellStyle cellStyle3, XSSFWorkbook workbook) {
- // HSSFCellStyle bcs = ExportExcel.createTitleCellStyle1(workbook);
- // bcs.setBorderBottom(BorderStyle.THIN); //下边框
- // bcs.setBorderLeft(BorderStyle.THIN);//左边框
- // bcs.setBorderTop(BorderStyle.THIN);//上边框
- // bcs.setBorderRight(BorderStyle.THIN);//右边框
- // bcs.setWrapText(true);
- XSSFRow row = null;
- XSSFCell cell = null;
- cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
- cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
- cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
- cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
- cellStyle1.setWrapText(true);
- cellStyle2.setBorderBottom(BorderStyle.THIN); //下边框
- cellStyle2.setBorderLeft(BorderStyle.THIN);//左边框
- cellStyle2.setBorderTop(BorderStyle.THIN);//上边框
- cellStyle2.setBorderRight(BorderStyle.THIN);//右边框
- cellStyle2.setWrapText(true);
- /*第一行*/
- sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));//2.申请年度单位
- /*第一行塞值*/
- row = sheet.createRow(0);
- cell = row.createCell(0);// ID
- cell.setCellStyle(cellStyle1);
- cell.setCellValue("注意:①请按照以下示例填写信息;②最多不超过5000行;③导入前,请记得删除示例行!");
- /*第二行塞值*/
- row = sheet.createRow(1);
- cell = row.createCell(0);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("竞争对手名称(必填)");
- cell = row.createCell(1);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("品牌名称(必填)");
- cell = row.createCell(2);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("优势信息");
- cell = row.createCell(3);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("劣势信息");
- cell = row.createCell(4);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("备注");
- /*第三行塞值*/
- row = sheet.createRow(2);
- cell = row.createCell(0);
- cell.setCellStyle(cellStyle3);
- cell.setCellValue("对手名称1");
- cell = row.createCell(1);
- cell.setCellStyle(cellStyle3);
- cell.setCellValue("品牌名称1");
- cell = row.createCell(2);
- cell.setCellStyle(cellStyle3);
- cell.setCellValue("优势信息1");
- cell = row.createCell(3);
- cell.setCellStyle(cellStyle3);
- cell.setCellValue("劣势信息1");
- cell = row.createCell(4);
- cell.setCellStyle(cellStyle3);
- cell.setCellValue("备注1");
- }
- /**
- * 2022-07-14 17:42:03
- * 设置表头
- **/
- public static void batchDetailErr(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFWorkbook workbook) {
- // HSSFCellStyle bcs = ExportExcel.createTitleCellStyle1(workbook);
- // bcs.setBorderBottom(BorderStyle.THIN); //下边框
- // bcs.setBorderLeft(BorderStyle.THIN);//左边框
- // bcs.setBorderTop(BorderStyle.THIN);//上边框
- // bcs.setBorderRight(BorderStyle.THIN);//右边框
- // bcs.setWrapText(true);
- XSSFRow row = null;
- XSSFCell cell = null;
- cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
- cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
- cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
- cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
- cellStyle1.setWrapText(true);
- /*第一行*/
- sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));//2.提示信息
- /*第一行塞值*/
- row = sheet.createRow(0);
- cell = row.createCell(0);// ID
- cell.setCellStyle(cellStyle1);
- cell.setCellValue("注意:①请按照以下示例填写信息;②最多不超过5000行;③导入前,请记得删除示例行!");
- /*第二行塞值*/
- row = sheet.createRow(1);
- cell = row.createCell(0);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("竞争对手名称(必填)");
- cell = row.createCell(1);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("品牌名称(必填)");
- cell = row.createCell(2);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("优势信息");
- cell = row.createCell(3);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("劣势信息");
- cell = row.createCell(4);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("备注");
- cell = row.createCell(5);
- cell.setCellStyle(cellStyle2);
- cell.setCellValue("错误信息");
- }
- }
|