暂降治理一期工作内容

This commit is contained in:
2024-04-19 14:33:14 +08:00
parent 0d71a74bdf
commit f2c3ce35ea
82 changed files with 4933 additions and 91 deletions

View File

@@ -45,7 +45,29 @@ public class ExcelUtil {
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.setContentType("application/octet-stream;charset=UTF-8");
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), pojoClass, dataSet);
ExportParams exportParams = new ExportParams();
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, dataSet);
workbook.write(outputStream);
} catch (IOException e) {
log.error(">>> 导出数据异常:{}", e.getMessage());
}
}
/**
* 指定名称、sheet名、数据下载报表
*
* @param fileName 文件名
*/
public static void exportExcel(String fileName, String sheetName, Class<?> pojoClass, Collection<?> dataSet) {
HttpServletResponse response = HttpServletUtil.getResponse();
try (ServletOutputStream outputStream = response.getOutputStream()) {
fileName = URLEncoder.encode(fileName, CharsetUtil.UTF_8);
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
response.setContentType("application/octet-stream;charset=UTF-8");
ExportParams exportParams = new ExportParams();
exportParams.setSheetName(sheetName);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, dataSet);
workbook.write(outputStream);
} catch (IOException e) {
log.error(">>> 导出数据异常:{}", e.getMessage());
@@ -57,8 +79,8 @@ public class ExcelUtil {
*
* @param fileName 文件名
*/
public static void exportExcel(ExportParams exportParams,String fileName, Class<?> pojoClass, Collection<?> dataSet) {
exportExcelPullDown(exportParams,fileName,null ,pojoClass, dataSet);
public static void exportExcel(ExportParams exportParams, String fileName, Class<?> pojoClass, Collection<?> dataSet) {
exportExcelPullDown(exportParams, fileName, null, pojoClass, dataSet);
}
@@ -72,10 +94,10 @@ public class ExcelUtil {
try (ServletOutputStream outputStream = response.getOutputStream()) {
fileName = URLEncoder.encode(fileName, CharsetUtil.UTF_8);
response.reset();
response.setHeader("Content-Disposition", "attachment;filename=" + fileName );
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
response.setContentType("application/octet-stream;charset=UTF-8");
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, dataSet);
if(CollUtil.isNotEmpty(pullDowns)){
if (CollUtil.isNotEmpty(pullDowns)) {
for (PullDown pullDown : pullDowns) {
ExcelUtil.selectList(workbook, pullDown.getFirstCol(), pullDown.getLastCol(), pullDown.getStrings().toArray(new String[]{}));
}
@@ -94,7 +116,7 @@ public class ExcelUtil {
CellStyle cellStyle = workbook.createCellStyle();
//获取单元格内容对象
Font font = workbook.createFont();
font.setFontHeightInPoints((short)12);
font.setFontHeightInPoints((short) 12);
//一定要装入 样式中才会生效
cellStyle.setFont(font);
//设置居中对齐
@@ -106,25 +128,25 @@ public class ExcelUtil {
String stringCellValue = cell.getStringCellValue();
if (stringCellValue.contains("*")) {
// 创建一个富文本
XSSFRichTextString xssfRichTextString = new XSSFRichTextString(stringCellValue);
XSSFRichTextString xssfRichTextString = new XSSFRichTextString(stringCellValue);
int startIndex = stringCellValue.indexOf("*");
int entIndex = stringCellValue.lastIndexOf("*");
if(entIndex!=0){
if (entIndex != 0) {
Font font3 = workbook.createFont();
font3.setFontHeightInPoints((short)12);
font3.setFontHeightInPoints((short) 12);
font3.setColor(Font.COLOR_NORMAL);
xssfRichTextString.applyFont(0, entIndex, font3);
}
//设置带*样式
Font font1 = workbook.createFont();
font1.setFontHeightInPoints((short)12);
font1.setFontHeightInPoints((short) 12);
font1.setColor(Font.COLOR_RED);
xssfRichTextString.applyFont(startIndex, entIndex+1, font1);
xssfRichTextString.applyFont(startIndex, entIndex + 1, font1);
//其他样式
Font font2 = workbook.createFont();
font2.setFontHeightInPoints((short)12);
font2.setFontHeightInPoints((short) 12);
font2.setColor(Font.COLOR_NORMAL);
xssfRichTextString.applyFont(entIndex+1, stringCellValue.length(), font2);
xssfRichTextString.applyFont(entIndex + 1, stringCellValue.length(), font2);
cell.setCellValue(xssfRichTextString);
}
}
@@ -175,11 +197,12 @@ public class ExcelUtil {
/**
* firstRow 開始行號 根据此项目默认为2(下标0开始)
* lastRow 根据此项目默认为最大65535
*
* @param firstCol 区域中第一个单元格的列号 (下标0开始)
* @param lastCol 区域中最后一个单元格的列号
* @param strings 下拉内容
* */
public static void selectList(Workbook workbook,int firstCol,int lastCol,String[] strings ){
* @param lastCol 区域中最后一个单元格的列号
* @param strings 下拉内容
*/
public static void selectList(Workbook workbook, int firstCol, int lastCol, String[] strings) {
Sheet sheet = workbook.getSheetAt(0);
// 生成下拉列表
@@ -189,12 +212,11 @@ public class ExcelUtil {
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)
dvHelper.createExplicitListConstraint(strings);
XSSFDataValidation validation =(XSSFDataValidation)dvHelper.createValidation(
XSSFDataValidation validation = (XSSFDataValidation) dvHelper.createValidation(
dvConstraint, cellRangeAddressList);
// 对sheet页生效
sheet.addValidationData(validation);
}
}