Pre Merge pull request !255 from 云飞扬/N/A

pull/255/MERGE
云飞扬 3 years ago committed by Gitee
commit 835bad8bf5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -2,10 +2,12 @@ package com.ruoyi.common.core.utils.poi;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
@ -455,6 +457,11 @@ public class ExcelUtil<T>
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
{
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
try {
response.addHeader("Content-Disposition", "attachment;FileName=" + URLEncoder.encode(title,"utf-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
response.setCharacterEncoding("utf-8");
this.init(list, sheetName, title, Type.EXPORT);
exportExcel(response);
@ -681,6 +688,7 @@ public class ExcelUtil<T>
if (!headerStyles.containsKey(key))
{
CellStyle style = wb.createCellStyle();
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
@ -714,6 +722,7 @@ public class ExcelUtil<T>
if (!styles.containsKey(key))
{
CellStyle style = wb.createCellStyle();
style = wb.createCellStyle();
style.setAlignment(excel.align());
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setBorderRight(BorderStyle.THIN);

@ -63,12 +63,12 @@ public class ${ClassName}Controller extends BaseController
*/
@RequiresPermissions("${permissionPrefix}:export")
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@PostMapping(value = "/export", produces = "application/octet-stream")
public void export(HttpServletResponse response, ${ClassName} ${className})
{
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
util.exportExcel(response, list, "${functionName}数据");
util.exportExcel(response, list, "${functionName}数据", "${functionName}数据");
}
/**

Loading…
Cancel
Save