CompetitorExcel.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package restcontroller.webmanage.sale.competitor;
  2. import org.apache.poi.ss.usermodel.BorderStyle;
  3. import org.apache.poi.ss.util.CellRangeAddress;
  4. import org.apache.poi.xssf.usermodel.*;
  5. public class CompetitorExcel {
  6. /**
  7. * 2022-07-14 17:41:39
  8. * 设置表格宽度(导入模板)
  9. **/
  10. public static void setBatchDetailSheetColumn1(XSSFSheet sheet) {
  11. sheet.setDefaultRowHeight((short) 600);
  12. short width = 2000;
  13. sheet.setColumnWidth((short) 0, width * 3);
  14. sheet.setColumnWidth((short) 1, width * 3);
  15. sheet.setColumnWidth((short) 2, width * 2);
  16. sheet.setColumnWidth((short) 3, width * 5);
  17. sheet.setColumnWidth((short) 4, width * 5);
  18. }
  19. /**
  20. * 2022-07-14 17:41:39
  21. * 设置表格宽度(返回错误Excel的样式)
  22. **/
  23. public static void setBatchDetailSheetColumn2(XSSFSheet sheet) {
  24. sheet.setDefaultRowHeight((short) 600);
  25. short width = 2000;
  26. sheet.setColumnWidth((short) 0, width * 3);
  27. sheet.setColumnWidth((short) 1, width * 3);
  28. sheet.setColumnWidth((short) 2, width * 2);
  29. sheet.setColumnWidth((short) 3, width * 5);
  30. sheet.setColumnWidth((short) 4, width * 5);
  31. sheet.setColumnWidth((short) 5, width * 5);
  32. }
  33. /**
  34. * 2022-07-14 17:42:03
  35. * 设置表头
  36. * cellStyle1 中文提示信息样式
  37. * cellStyle2 标题提示信息样式
  38. * cellStyle3 正文提示信息样式
  39. **/
  40. public static void batchDetail(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFCellStyle cellStyle3, XSSFWorkbook workbook) {
  41. // HSSFCellStyle bcs = ExportExcel.createTitleCellStyle1(workbook);
  42. // bcs.setBorderBottom(BorderStyle.THIN); //下边框
  43. // bcs.setBorderLeft(BorderStyle.THIN);//左边框
  44. // bcs.setBorderTop(BorderStyle.THIN);//上边框
  45. // bcs.setBorderRight(BorderStyle.THIN);//右边框
  46. // bcs.setWrapText(true);
  47. XSSFRow row = null;
  48. XSSFCell cell = null;
  49. cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
  50. cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
  51. cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
  52. cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
  53. cellStyle1.setWrapText(true);
  54. cellStyle2.setBorderBottom(BorderStyle.THIN); //下边框
  55. cellStyle2.setBorderLeft(BorderStyle.THIN);//左边框
  56. cellStyle2.setBorderTop(BorderStyle.THIN);//上边框
  57. cellStyle2.setBorderRight(BorderStyle.THIN);//右边框
  58. cellStyle2.setWrapText(true);
  59. /*第一行*/
  60. sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));//2.申请年度单位
  61. /*第一行塞值*/
  62. row = sheet.createRow(0);
  63. cell = row.createCell(0);// ID
  64. cell.setCellStyle(cellStyle1);
  65. cell.setCellValue("注意:①请按照以下示例填写信息;②最多不超过5000行;③导入前,请记得删除示例行!");
  66. /*第二行塞值*/
  67. row = sheet.createRow(1);
  68. cell = row.createCell(0);
  69. cell.setCellStyle(cellStyle2);
  70. cell.setCellValue("竞争对手名称(必填)");
  71. cell = row.createCell(1);
  72. cell.setCellStyle(cellStyle2);
  73. cell.setCellValue("品牌名称(必填)");
  74. cell = row.createCell(2);
  75. cell.setCellStyle(cellStyle2);
  76. cell.setCellValue("优势信息");
  77. cell = row.createCell(3);
  78. cell.setCellStyle(cellStyle2);
  79. cell.setCellValue("劣势信息");
  80. cell = row.createCell(4);
  81. cell.setCellStyle(cellStyle2);
  82. cell.setCellValue("备注");
  83. /*第三行塞值*/
  84. row = sheet.createRow(2);
  85. cell = row.createCell(0);
  86. cell.setCellStyle(cellStyle3);
  87. cell.setCellValue("对手名称1");
  88. cell = row.createCell(1);
  89. cell.setCellStyle(cellStyle3);
  90. cell.setCellValue("品牌名称1");
  91. cell = row.createCell(2);
  92. cell.setCellStyle(cellStyle3);
  93. cell.setCellValue("优势信息1");
  94. cell = row.createCell(3);
  95. cell.setCellStyle(cellStyle3);
  96. cell.setCellValue("劣势信息1");
  97. cell = row.createCell(4);
  98. cell.setCellStyle(cellStyle3);
  99. cell.setCellValue("备注1");
  100. }
  101. /**
  102. * 2022-07-14 17:42:03
  103. * 设置表头
  104. **/
  105. public static void batchDetailErr(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFWorkbook workbook) {
  106. // HSSFCellStyle bcs = ExportExcel.createTitleCellStyle1(workbook);
  107. // bcs.setBorderBottom(BorderStyle.THIN); //下边框
  108. // bcs.setBorderLeft(BorderStyle.THIN);//左边框
  109. // bcs.setBorderTop(BorderStyle.THIN);//上边框
  110. // bcs.setBorderRight(BorderStyle.THIN);//右边框
  111. // bcs.setWrapText(true);
  112. XSSFRow row = null;
  113. XSSFCell cell = null;
  114. cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
  115. cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
  116. cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
  117. cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
  118. cellStyle1.setWrapText(true);
  119. /*第一行*/
  120. sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));//2.提示信息
  121. /*第一行塞值*/
  122. row = sheet.createRow(0);
  123. cell = row.createCell(0);// ID
  124. cell.setCellStyle(cellStyle1);
  125. cell.setCellValue("注意:①请按照以下示例填写信息;②最多不超过5000行;③导入前,请记得删除示例行!");
  126. /*第二行塞值*/
  127. row = sheet.createRow(1);
  128. cell = row.createCell(0);
  129. cell.setCellStyle(cellStyle2);
  130. cell.setCellValue("竞争对手名称(必填)");
  131. cell = row.createCell(1);
  132. cell.setCellStyle(cellStyle2);
  133. cell.setCellValue("品牌名称(必填)");
  134. cell = row.createCell(2);
  135. cell.setCellStyle(cellStyle2);
  136. cell.setCellValue("优势信息");
  137. cell = row.createCell(3);
  138. cell.setCellStyle(cellStyle2);
  139. cell.setCellValue("劣势信息");
  140. cell = row.createCell(4);
  141. cell.setCellStyle(cellStyle2);
  142. cell.setCellValue("备注");
  143. cell = row.createCell(5);
  144. cell.setCellStyle(cellStyle2);
  145. cell.setCellValue("错误信息");
  146. }
  147. }