|
|
@@ -1,19 +1,12 @@
|
|
|
package com.goafanti.common.utils.word;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.goafanti.RD.bo.OutWordRdDetails;
|
|
|
-import com.goafanti.common.constant.AFTConstants;
|
|
|
-import com.goafanti.common.utils.DateUtils;
|
|
|
-import com.goafanti.common.utils.StringUtils;
|
|
|
import com.goafanti.common.utils.excel.FileUtils;
|
|
|
|
|
|
|
|
|
-import com.goafanti.common.utils.pdf.PDFUtils;
|
|
|
import com.lowagie.text.*;
|
|
|
import com.lowagie.text.Font;
|
|
|
-import com.lowagie.text.pdf.BaseFont;
|
|
|
import com.lowagie.text.rtf.RtfWriter2;
|
|
|
-import com.sushengren.easyword.EasyWord;
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
|
|
|
|
@@ -22,47 +15,17 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.awt.*;
|
|
|
import java.io.*;
|
|
|
import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
public class WordUtils {
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 导出word文件
|
|
|
- */
|
|
|
- public void download(HttpServletResponse response, String tableName, Object data,String uploadPath) throws IOException {
|
|
|
|
|
|
- if(StringUtils.isEmpty(tableName) ){
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- String realFileName = tableName+DateUtils.parseDateToStr(AFTConstants.YYYYMMDDHHMMSS, new Date())+".docx";
|
|
|
- response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
- FileUtils.setAttachmentResponseHeader(response, tableName,realFileName);
|
|
|
- String url=uploadPath+"/tmp/RD_details_word_template.docx";
|
|
|
- //获取resources下目中录模板文件
|
|
|
-// File file = new ClassPathResource(url).getFile();
|
|
|
- File file=new File(url);
|
|
|
- //以流的形式 获取resources下目中录模板文件
|
|
|
-// InputStream file = new ClassPathResource(url).getInputStream();
|
|
|
- EasyWord.Builder of = EasyWord.of(file);
|
|
|
- of.doWrite(data);
|
|
|
- of.toOutputStream(response.getOutputStream());
|
|
|
- } catch (Exception e) {
|
|
|
- // 重置response
|
|
|
- response.reset();
|
|
|
- response.setContentType("application/json");
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("status", "failure");
|
|
|
- map.put("message", "下载文件失败" + e.getMessage());
|
|
|
- response.getWriter().println(JSON.toJSONString(map));
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- public void pushWord(OutWordRdDetails data, HttpServletResponse response, String tableName, String attName, String realFileName) {
|
|
|
+ public void pushWord(OutWordRdDetails data, HttpServletResponse response, String uploadPath) {
|
|
|
+ String tableName = data.getRdName();
|
|
|
+ String realFileName = uploadPath+"/tmp/"+new Date().getTime() + ".doc";
|
|
|
+ String attName = data.getRdName()+new Date().getTime() + ".doc";
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
Document document=new Document(PageSize.A4);
|
|
|
try {
|
|
|
FileUtils.setAttachmentResponseHeader(response, tableName,attName);
|