【修改】文件导出新增文件名称编写
This commit is contained in:
parent
a000ad6401
commit
c6da517c99
|
|
@ -7,6 +7,18 @@
|
|||
<artifactId>zlpt-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>10</source>
|
||||
<target>10</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>zlpt-common-core</artifactId>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ 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.nio.charset.StandardCharsets;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
|
@ -61,6 +63,8 @@ import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
|||
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* Excel相关处理
|
||||
|
|
@ -457,6 +461,28 @@ public class ExcelUtil<T>
|
|||
exportExcel(response, list, sheetName, StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
* @param response 返回数据
|
||||
* @param list 导出数据集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @return 结果
|
||||
*
|
||||
* 可以设置文件名称
|
||||
*/
|
||||
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title,String fileName)
|
||||
{
|
||||
|
||||
String encodedFileName = null;
|
||||
encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8);
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedFileName + "\"");
|
||||
this.init(list, sheetName, title, Excel.Type.EXPORT);
|
||||
exportExcel(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对list数据源将其里面的数据导入到excel表单
|
||||
*
|
||||
|
|
@ -468,8 +494,13 @@ public class ExcelUtil<T>
|
|||
*/
|
||||
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
|
||||
{
|
||||
|
||||
String fileName = "物料主数据导入模板.xlsx";
|
||||
String encodedFileName = null;
|
||||
encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8);
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedFileName + "\"");
|
||||
this.init(list, sheetName, title, Excel.Type.EXPORT);
|
||||
exportExcel(response);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ public class BmCompanyInfoController extends BaseController {
|
|||
public void exportExcel(HttpServletResponse response){
|
||||
|
||||
ExcelUtil<BmCompanyInfo> bmCompanyInfoExcelUtil = new ExcelUtil<>(BmCompanyInfo.class);
|
||||
bmCompanyInfoExcelUtil.exportExcel(response,bmCompanyInfoService.selectList(new BmCompanyDto()),"企业入驻信息");
|
||||
bmCompanyInfoExcelUtil.exportExcel(response,bmCompanyInfoService.selectList(new BmCompanyDto()),"企业入驻信息","","企业入驻信息");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public class BmCompanyTypeController extends BaseController {
|
|||
public void exportExcel(HttpServletResponse response){
|
||||
|
||||
ExcelUtil<SysDic> sysDicExcelUtil = new ExcelUtil<>(SysDic.class);
|
||||
sysDicExcelUtil.exportExcel(response,bmCompanyTypeService.selectCompanyTypeList(new SysDic()),"企业类型");
|
||||
sysDicExcelUtil.exportExcel(response,bmCompanyTypeService.selectCompanyTypeList(new SysDic()),"企业类型","","企业类型");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class BusinessOpenController extends BaseController {
|
|||
public void exportExcel(HttpServletResponse response){
|
||||
|
||||
ExcelUtil<BusinessOpenVo> businessOpenVoExcelUtil = new ExcelUtil<>(BusinessOpenVo.class);
|
||||
businessOpenVoExcelUtil.exportExcel(response,businessOpenService.selectList(new BmCompanyDto()),"企业业务开通数据");
|
||||
businessOpenVoExcelUtil.exportExcel(response,businessOpenService.selectList(new BmCompanyDto()),"企业业务开通数据","","企业业务开通数据");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue