Browse Source

修改模板提示

appendLagreFile
Jiaju Zhuang 2 years ago
parent
commit
eb8c7d5446
  1. 14
      easyexcel-core/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java
  2. 4
      easyexcel-core/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java
  3. 1
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

14
easyexcel-core/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java

@ -66,7 +66,6 @@ public class ExcelWriterBuilder extends AbstractExcelWriterParameterBuilder<Exce
return this; return this;
} }
public ExcelWriterBuilder excelType(ExcelTypeEnum excelType) { public ExcelWriterBuilder excelType(ExcelTypeEnum excelType) {
writeWorkbook.setExcelType(excelType); writeWorkbook.setExcelType(excelType);
return this; return this;
@ -95,21 +94,32 @@ public class ExcelWriterBuilder extends AbstractExcelWriterParameterBuilder<Exce
return this; return this;
} }
/**
* Template file.
* This file is read into memory, excessive cases can lead to OOM.
*/
public ExcelWriterBuilder withTemplate(InputStream templateInputStream) { public ExcelWriterBuilder withTemplate(InputStream templateInputStream) {
writeWorkbook.setTemplateInputStream(templateInputStream); writeWorkbook.setTemplateInputStream(templateInputStream);
return this; return this;
} }
/**
* Template file.
* This file is read into memory, excessive cases can lead to OOM.
*/
public ExcelWriterBuilder withTemplate(File templateFile) { public ExcelWriterBuilder withTemplate(File templateFile) {
writeWorkbook.setTemplateFile(templateFile); writeWorkbook.setTemplateFile(templateFile);
return this; return this;
} }
/**
* Template file.
* This file is read into memory, excessive cases can lead to OOM.
*/
public ExcelWriterBuilder withTemplate(String pathName) { public ExcelWriterBuilder withTemplate(String pathName) {
return withTemplate(new File(pathName)); return withTemplate(new File(pathName));
} }
public ExcelWriter build() { public ExcelWriter build() {
return new ExcelWriter(writeWorkbook); return new ExcelWriter(writeWorkbook);
} }

4
easyexcel-core/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java

@ -49,7 +49,8 @@ public class WriteWorkbook extends WriteBasicParameter {
private InputStream templateInputStream; private InputStream templateInputStream;
/** /**
* Template file * Template file.
* This file is read into memory, excessive cases can lead to OOM.
* <p> * <p>
* If 'inputStream' and 'file' all not empty, file first * If 'inputStream' and 'file' all not empty, file first
*/ */
@ -66,7 +67,6 @@ public class WriteWorkbook extends WriteBasicParameter {
* Whether the encryption * Whether the encryption
* <p> * <p>
* WARRING:Encryption is when the entire file is read into memory, so it is very memory intensive. * WARRING:Encryption is when the entire file is read into memory, so it is very memory intensive.
*
*/ */
private String password; private String password;
/** /**

1
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

@ -401,6 +401,7 @@ public class WriteTest {
String templateFileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx"; String templateFileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
String fileName = TestFileUtil.getPath() + "templateWrite" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "templateWrite" + System.currentTimeMillis() + ".xlsx";
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里要注意 withTemplate 的模板文件会全量存储在内存里面,所以尽量不要用于追加文件,如果文件模板文件过大会OOM
EasyExcel.write(fileName, DemoData.class).withTemplate(templateFileName).sheet().doWrite(data()); EasyExcel.write(fileName, DemoData.class).withTemplate(templateFileName).sheet().doWrite(data());
} }

Loading…
Cancel
Save