|
@@ -21,6 +21,7 @@ import rx.internal.util.LinkedArrayList;
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import java.awt.*;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -57,24 +58,28 @@ public class MathController extends BaseController {
|
|
|
}
|
|
|
|
|
|
String path = ConstantFilePath.EXCEL_PATH + DateUtil.format(new Date(), DateExtUtil.dateStyle11) + ".docx";
|
|
|
- try (Word07Writer writer = new Word07Writer()){
|
|
|
- // 添加段落(标题)
|
|
|
- writer.addText(new Font("方正小标宋简体", Font.PLAIN, 22), "我是第一部分", "我是第二部分");
|
|
|
- // 添加段落(正文)
|
|
|
- writer.addText(new Font("宋体", Font.PLAIN, 22), "我是正文第一部分", "我是正文第二部分");
|
|
|
- for (String s : out) {
|
|
|
- writer.addText(new Font("宋体", Font.PLAIN, 22), s);
|
|
|
- }
|
|
|
-
|
|
|
- // 写出到文件
|
|
|
- writer.flush(FileUtil.file(path));
|
|
|
+ Word07Writer writer = new Word07Writer();
|
|
|
+ // 添加段落(标题)
|
|
|
+ for (String s : out) {
|
|
|
+ writer.addText(new Font("宋体", Font.PLAIN, 22), s);
|
|
|
}
|
|
|
|
|
|
+ // 写出到文件
|
|
|
+ writer.flush(FileUtil.file(path));
|
|
|
+
|
|
|
this.response.setContentType(ContentType.OCTET_STREAM.getValue());
|
|
|
this.response.setHeader("Content-Disposition", "attachment;filename=" + FileUtil.getName(path));
|
|
|
ServletOutputStream outputStream = this.response.getOutputStream();
|
|
|
- int read = FileUtil.getInputStream(path).read();
|
|
|
- outputStream.write(read);
|
|
|
+ BufferedInputStream in = FileUtil.getInputStream(path);
|
|
|
+
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead;
|
|
|
+ while ((bytesRead = in.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ outputStream.flush();
|
|
|
+ in.close();
|
|
|
+ outputStream.close();
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|