main
黄海 2 years ago
parent 8b0d6372f1
commit eddb5d76e4

@ -29,8 +29,10 @@ import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.ParseException;
import java.util.*;
@ -822,7 +824,21 @@ public class CollectController extends Controller {
if (type_id == 2) {
String pdfPath = excelPath.replace(".xlsx", ".pdf");
AsposeUtil.xls2pdf(excelPath, pdfPath);
renderFile(new File(excelPath), pdf_filename);
HttpServletResponse response = getResponse();
BufferedInputStream br = new BufferedInputStream(new FileInputStream(excelPath));
byte[] buf = new byte[1024];
int len;
response.reset(); // 非常重要
URL u = new URL("file:///" + excelPath);
response.setContentType(u.openConnection().getContentType());
String fileName = pdf_filename;
response.setHeader("Content-Disposition", "inline; filename=" + fileName);
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
renderNull();
}
}

Loading…
Cancel
Save