parent
e03cebac57
commit
10a1650fe1
|
|
@ -2,10 +2,12 @@ package com.ruoyi.common.core.utils.poi;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
@ -455,6 +457,11 @@ public class ExcelUtil<T>
|
||||||
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
|
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
|
||||||
{
|
{
|
||||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
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");
|
response.setCharacterEncoding("utf-8");
|
||||||
this.init(list, sheetName, title, Type.EXPORT);
|
this.init(list, sheetName, title, Type.EXPORT);
|
||||||
exportExcel(response);
|
exportExcel(response);
|
||||||
|
|
@ -681,6 +688,7 @@ public class ExcelUtil<T>
|
||||||
if (!headerStyles.containsKey(key))
|
if (!headerStyles.containsKey(key))
|
||||||
{
|
{
|
||||||
CellStyle style = wb.createCellStyle();
|
CellStyle style = wb.createCellStyle();
|
||||||
|
style = wb.createCellStyle();
|
||||||
style.cloneStyleFrom(styles.get("data"));
|
style.cloneStyleFrom(styles.get("data"));
|
||||||
style.setAlignment(HorizontalAlignment.CENTER);
|
style.setAlignment(HorizontalAlignment.CENTER);
|
||||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
|
@ -714,6 +722,7 @@ public class ExcelUtil<T>
|
||||||
if (!styles.containsKey(key))
|
if (!styles.containsKey(key))
|
||||||
{
|
{
|
||||||
CellStyle style = wb.createCellStyle();
|
CellStyle style = wb.createCellStyle();
|
||||||
|
style = wb.createCellStyle();
|
||||||
style.setAlignment(excel.align());
|
style.setAlignment(excel.align());
|
||||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
style.setBorderRight(BorderStyle.THIN);
|
style.setBorderRight(BorderStyle.THIN);
|
||||||
|
|
|
||||||
|
|
@ -63,12 +63,12 @@ public class ${ClassName}Controller extends BaseController
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("${permissionPrefix}:export")
|
@RequiresPermissions("${permissionPrefix}:export")
|
||||||
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
|
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
|
||||||
@PostMapping("/export")
|
@PostMapping(value = "/export", produces = "application/octet-stream")
|
||||||
public void export(HttpServletResponse response, ${ClassName} ${className})
|
public void export(HttpServletResponse response, ${ClassName} ${className})
|
||||||
{
|
{
|
||||||
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
|
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
|
||||||
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
|
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
|
||||||
util.exportExcel(response, list, "${functionName}数据");
|
util.exportExcel(response, list, "${functionName}数据", "${functionName}数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue