1.前端查询条件显示:
type=“number”
v-model=“queryCondition[item.fieldName][0]”
placeholder=“最小值”
@change=“getMaxName(item.fieldName)”
>
-
type=“number”
v-model=“queryCondition[item.fieldName][1]”
placeholder=“最大值”
@change=“getMaxName(item.fieldName)”
>
2.前端添加方法,使用post请求,将自定义字段封装为对象进行传递
async exportExcel() {
// 最大值 最小值必须都填写
if (this.maxName && this.queryCondition[this.maxName] && this.queryCondition[this.maxName].length) {
if (this.queryCondition[this.maxName].length !== 2) {
this.KaTeX parse error: Expected 'EOF', got '}' at position 61: …eturn; }̲ } …http.post(“/report/exportExcel”, this.queryCondition);
if (res.code === 200) {
fileExport.name(res.msg);
} else {
this.$message.error(res.msg);
}
}
3.在后端Controller添加导出方法,根据接收到的对象信息,查询报表内容
@RequestMapping(“/exportExcel”)
public AjaxResult exportExcel(@RequestBody JSONObject jsonObject, HttpServletResponse response) throws IOException {
OutputStream ouputStream = null;
String fileName = “报表详情列表”;
try {
List
if(CollectionUtil.isNotEmpty(detailList)){
try {
//获取报表详情的表头
LinkedHashMap
4.报表内容的自定义方法解析
private SXSSFWorkbook exportDetail(List kyList, List
Sheet sheet = workbook.createSheet();
workbook.setSheetName(index, “报表详情列表”);
// 生成一个样式CellStyle style1 = workbook.createCellStyle();// 设置背景色style1.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE.getIndex());style1.setFillPattern(FillPatternType.SOLID_FOREGROUND);//设置边框style1.setBorderBottom(BorderStyle.THIN);style1.setBorderLeft(BorderStyle.THIN);style1.setBorderRight(BorderStyle.THIN);style1.setBorderTop(BorderStyle.THIN);style1.setAlignment(HorizontalAlignment.CENTER);// 设置字体Font font1 = workbook.createFont();font1.setFontName("仿宋_GB2312");font1.setColor(IndexedColors.OLIVE_GREEN.index);font1.setFontHeightInPoints((short) 14);// 把字体应用到当前的样式style1.setFont(font1);for(int i =0; i < kyList.size(); i++){sheet.setColumnWidth(i, 12000);}//生成一行Row row2 = sheet.createRow(0);Cell cell1;for (int k = 0; k < kyList.size(); k++) {cell1 = row2.createCell(k);cell1.setCellValue(String.valueOf(kyList.get(k)));cell1.setCellStyle(style1);}sheet = workbook.getSheetAt(index);// 生成一个样式CellStyle style3 = workbook.createCellStyle();//设置边框style3.setBorderBottom(BorderStyle.THIN);style3.setBorderLeft(BorderStyle.THIN);style3.setBorderRight(BorderStyle.THIN);style3.setBorderTop(BorderStyle.THIN);style3.setAlignment(HorizontalAlignment.CENTER);style3.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中Font font3 = workbook.createFont();font3.setFontName("仿宋_GB2312");font3.setColor(IndexedColors.BLACK.index);font3.setFontHeightInPoints((short) 10);font3.setBold(true);// 把字体应用到当前的样式style3.setFont(font3);style3.setWrapText(true);Row row3;Cell cell3;for (int i = 0; i < detailList.size(); i++) {LinkedHashMap
上一篇:C语言——每周刷题题集(第一周)