|
@@ -42,7 +42,7 @@ public class ExcelUtils {
|
|
|
* @param type 导出类型(1 人员 2 部门)
|
|
|
* @param response
|
|
|
*/
|
|
|
- public static void downloadExcel(List<DownloadInfoVo> list,Integer name,Integer type, HttpServletResponse response){
|
|
|
+ public static void downloadExcel(List<DownloadInfoVo> list,Integer name,Integer type,String createTime,String endTime,String dimension, HttpServletResponse response){
|
|
|
try {
|
|
|
//创建一个空的工作薄
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
|
@@ -81,16 +81,57 @@ public class ExcelUtils {
|
|
|
}
|
|
|
}
|
|
|
//设置文件的打开方式和mime类型
|
|
|
- Date date = new Date();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
- String dateStr = sdf.format(date);
|
|
|
- String filename = DownloadNameEnum.getMessage(name) + DownloadTypeEnum.getMessage(type)
|
|
|
- + dateStr + ".xlsx";
|
|
|
- ServletOutputStream outputStream = response.getOutputStream();
|
|
|
- response.addHeader("Content-Disposition", "attachment;filename=" +
|
|
|
- new String(filename.getBytes(), "ISO8859-1"));
|
|
|
+ String fileName = null;
|
|
|
+ if (createTime != null && endTime != null){
|
|
|
+ createTime = createTime.replaceAll("-","");
|
|
|
+ endTime = endTime.replaceAll("-","");
|
|
|
+ if (name == 1 || name == 5){
|
|
|
+ fileName = URLEncoder.encode(
|
|
|
+ DownloadNameEnum.getMessage(name) + "-" + DownloadTypeEnum.getMessage(type) + "访问量" + "-"
|
|
|
+ + createTime + "-" + endTime, "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ } else {
|
|
|
+ fileName = URLEncoder.encode(
|
|
|
+ DownloadNameEnum.getMessage(name) + "-" + DownloadTypeEnum.getMessage(type) + "创建量" + "-"
|
|
|
+ + createTime + "-" + endTime, "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (name == 1 || name == 5){
|
|
|
+ if (("total").equals(dimension)){
|
|
|
+ fileName = URLEncoder.encode(
|
|
|
+ DownloadNameEnum.getMessage(name) + "-" + DownloadTypeEnum.getMessage(type) + "访问量" + "-"
|
|
|
+ + "全部", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ } else if (("year").equals(dimension)){
|
|
|
+ fileName = URLEncoder.encode(
|
|
|
+ DownloadNameEnum.getMessage(name) + "-" + DownloadTypeEnum.getMessage(type) + "访问量" + "-"
|
|
|
+ + "年", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ } else if (("month").equals(dimension)){
|
|
|
+ fileName = URLEncoder.encode(
|
|
|
+ DownloadNameEnum.getMessage(name) + "-" + DownloadTypeEnum.getMessage(type) + "访问量" + "-"
|
|
|
+ + "月", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (("total").equals(dimension)){
|
|
|
+ fileName = URLEncoder.encode(
|
|
|
+ DownloadNameEnum.getMessage(name) + "-" + DownloadTypeEnum.getMessage(type) + "创建量" + "-"
|
|
|
+ + "全部", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ } else if (("year").equals(dimension)){
|
|
|
+ fileName = URLEncoder.encode(
|
|
|
+ DownloadNameEnum.getMessage(name) + "-" + DownloadTypeEnum.getMessage(type) + "创建量" + "-"
|
|
|
+ + "年", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ } else if (("month").equals(dimension)){
|
|
|
+ fileName = URLEncoder.encode(
|
|
|
+ DownloadNameEnum.getMessage(name) + "-" + DownloadTypeEnum.getMessage(type) + "创建量" + "-"
|
|
|
+ + "月", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
+ response.addHeader("blob","true");
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
workbook.write(outputStream);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|