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.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;
@ -255,7 +257,7 @@ public class ExcelUtil<T>
/** /**
* excellist * excellist
* *
* @param is * @param is
* @return * @return
*/ */
@ -266,7 +268,7 @@ public class ExcelUtil<T>
/** /**
* excellist * excellist
* *
* @param is * @param is
* @param titleNum * @param titleNum
* @return * @return
@ -278,7 +280,7 @@ public class ExcelUtil<T>
/** /**
* excellist * excellist
* *
* @param sheetName * @param sheetName
* @param titleNum * @param titleNum
* @param is * @param is
@ -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);
@ -488,7 +495,7 @@ public class ExcelUtil<T>
/** /**
* listexcel * listexcel
* *
* @return * @return
*/ */
public void exportExcel(HttpServletResponse response) public void exportExcel(HttpServletResponse response)
@ -550,7 +557,7 @@ public class ExcelUtil<T>
/** /**
* excel * excel
* *
* @param index * @param index
* @param row * @param row
*/ */
@ -614,7 +621,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param wb * @param wb
* @return * @return
*/ */
@ -667,7 +674,7 @@ public class ExcelUtil<T>
/** /**
* Excel * Excel
* *
* @param wb * @param wb
* @return * @return
*/ */
@ -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);
@ -700,7 +708,7 @@ public class ExcelUtil<T>
/** /**
* Excel * Excel
* *
* @param wb * @param wb
* @return * @return
*/ */
@ -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);
@ -762,7 +771,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param value * @param value
* @param attr * @param attr
* @param cell * @param cell
@ -909,7 +918,7 @@ public class ExcelUtil<T>
/** /**
* POI XSSFSheet * POI XSSFSheet
* *
* @param sheet * @param sheet
* @param textlist * @param textlist
* @param promptContent * @param promptContent
@ -983,7 +992,7 @@ public class ExcelUtil<T>
/** /**
* =0,=1,=2 * =0,=1,=2
* *
* @param propertyValue * @param propertyValue
* @param converterExp * @param converterExp
* @param separator * @param separator
@ -1224,7 +1233,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param sheetNo sheet * @param sheetNo sheet
* @param index * @param index
*/ */
@ -1241,7 +1250,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param row * @param row
* @param column * @param column
* @return * @return
@ -1301,7 +1310,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param row * @param row
* @return * @return
*/ */
@ -1324,7 +1333,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param dateFormat * @param dateFormat
* @param val * @param val
* @return * @return
@ -1390,7 +1399,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param name * @param name
* @param pojoClass * @param pojoClass
* @return * @return

@ -27,7 +27,7 @@ import com.ruoyi.common.core.web.page.TableDataInfo;
/** /**
* ${functionName}Controller * ${functionName}Controller
* *
* @author ${author} * @author ${author}
* @date ${datetime} * @date ${datetime}
*/ */
@ -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…
Cancel
Save