|
@@ -1,6 +1,7 @@
|
|
|
package com.qmth.cqb.utils.word;
|
|
|
|
|
|
import com.qmth.cqb.utils.CommonUtils;
|
|
|
+import com.qmth.cqb.utils.ZipUtils;
|
|
|
import com.qmth.cqb.utils.enums.QuesUnit;
|
|
|
import freemarker.template.Configuration;
|
|
|
import freemarker.template.Template;
|
|
@@ -58,6 +59,7 @@ import java.io.*;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
/**
|
|
|
* docx处理工具类 Created by songyue on 17/3/10.
|
|
@@ -656,8 +658,8 @@ public final class DocxProcessUtil {
|
|
|
* @param dataMap
|
|
|
* @param fileName
|
|
|
*/
|
|
|
- public static void exportPaper(Map dataMap, String fileName) throws Exception {
|
|
|
- exportWord(dataMap, fileName, PAPER_TEMPLATE);
|
|
|
+ public static void exportPaper(Map dataMap, String fileName,String paperTemplate) throws Exception {
|
|
|
+ exportWord(dataMap, fileName, paperTemplate);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -666,8 +668,8 @@ public final class DocxProcessUtil {
|
|
|
* @param dataMap
|
|
|
* @param fileName
|
|
|
*/
|
|
|
- public static void exportAnswer(Map dataMap, String fileName) throws Exception {
|
|
|
- exportWord(dataMap, fileName, ANSWER_TEMPLATE);
|
|
|
+ public static void exportAnswer(Map dataMap, String fileName,String answerTemplate) throws Exception {
|
|
|
+ exportWord(dataMap, fileName, answerTemplate);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -812,16 +814,18 @@ public final class DocxProcessUtil {
|
|
|
* @param response
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public static void processDownload(String fileName, HttpServletResponse response) throws Exception {
|
|
|
- String filePath = TEMP_FILE_EXP + fileName + DOCX_SUFFIX;
|
|
|
- InputStream inputStream = new FileInputStream(filePath);
|
|
|
- OutputStream outputStream = response.getOutputStream();
|
|
|
- // 设置强制下载不打开
|
|
|
- response.setContentType("application/octet-stream;charset=utf-8");
|
|
|
- // 设置文件名
|
|
|
- response.addHeader("Content-Disposition",
|
|
|
- "attachment;fileName=" + new String(fileName.getBytes("UTF-8"), "iso-8859-1") + DOCX_SUFFIX);
|
|
|
- IOUtils.copyLarge(inputStream, outputStream);
|
|
|
+ public static void processDownload(List<String> fileNames, HttpServletResponse response) throws Exception {
|
|
|
+ String zipFileName = fileNames.get(0);
|
|
|
+ response.setHeader("Content-Disposition","attachment; filename="+new String(zipFileName.getBytes("UTF-8"), "iso-8859-1")+".zip");
|
|
|
+ // 设置强制下载不打开
|
|
|
+ response.setContentType("application/octet-stream;charset=utf-8");
|
|
|
+ ZipOutputStream out = new ZipOutputStream(response.getOutputStream());
|
|
|
+ for(String fileName:fileNames){
|
|
|
+ ZipUtils.doCompress(TEMP_FILE_EXP+fileName+DOCX_SUFFIX, out);
|
|
|
+ response.flushBuffer();
|
|
|
+ }
|
|
|
+ out.close();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|