Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	example/pom.xml
  • Loading branch information
liaochong committed Sep 29, 2019
2 parents ef5f3d8 + 8d6ce88 commit c6eac81
Show file tree
Hide file tree
Showing 64 changed files with 2,899 additions and 1,216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public class BeetlExcelBuilderExampleController {
*/
@GetMapping("/beetl/example")
public void build(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new BeetlExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();
try (ExcelBuilder excelBuilder = new BeetlExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder.template("/templates/beetlToExcelExample.btl").build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
Workbook workbook = excelBuilder.template("/templates/beetlToExcelExample.btl").build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
}
}

/**
Expand All @@ -44,11 +45,12 @@ public void build(HttpServletResponse response) throws IOException {
*/
@GetMapping("/beetl/defaultStyle/example")
public void buildWithDefaultStyle(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new BeetlExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();
try (ExcelBuilder excelBuilder = new BeetlExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder.template("/templates/beetlToExcelExample.btl").useDefaultStyle().build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
Workbook workbook = excelBuilder.template("/templates/beetlToExcelExample.btl").useDefaultStyle().build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
}
}

/**
Expand All @@ -58,15 +60,16 @@ public void buildWithDefaultStyle(HttpServletResponse response) throws IOExcepti
*/
@GetMapping("/beetl/xls/example")
public void buildWithXLS(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new BeetlExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/beetlToExcelExample.btl")
.workbookType(WorkbookType.XLS)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
try (ExcelBuilder excelBuilder = new BeetlExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/beetlToExcelExample.btl")
.workbookType(WorkbookType.XLS)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
}
}

/**
Expand All @@ -76,15 +79,16 @@ public void buildWithXLS(HttpServletResponse response) throws IOException {
*/
@GetMapping("/beetl/xlsx/example")
public void buildWithXLSX(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new BeetlExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/beetlToExcelExample.btl")
.workbookType(WorkbookType.XLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
try (ExcelBuilder excelBuilder = new BeetlExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/beetlToExcelExample.btl")
.workbookType(WorkbookType.XLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
}
}

/**
Expand All @@ -94,15 +98,16 @@ public void buildWithXLSX(HttpServletResponse response) throws IOException {
*/
@GetMapping("/beetl/sxlsx/example")
public void buildWithSXLSX(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new BeetlExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/beetlToExcelExample.btl")
.workbookType(WorkbookType.SXLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
try (ExcelBuilder excelBuilder = new BeetlExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/beetlToExcelExample.btl")
.workbookType(WorkbookType.SXLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "beetl_excel", response);
}
}

private Map<String, Object> getDataMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.liaochong.example.pojo.ArtCrowd;
import com.github.liaochong.myexcel.core.DefaultExcelBuilder;
import com.github.liaochong.myexcel.core.strategy.AutoWidthStrategy;
import com.github.liaochong.myexcel.core.strategy.WidthStrategy;
import com.github.liaochong.myexcel.utils.AttachmentExportUtil;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -37,17 +38,17 @@ public void defaultBuildWithNoStyle(HttpServletResponse response) throws Excepti
@GetMapping("/default/autoWidth/example")
public void defaultBuildWithAutoWidth(HttpServletResponse response) throws Exception {
List<ArtCrowd> dataList = this.getDataList();
Workbook workbook = DefaultExcelBuilder.of(ArtCrowd.class).autoWidthStrategy(AutoWidthStrategy.AUTO_WIDTH).build(dataList);
Workbook workbook = DefaultExcelBuilder.of(ArtCrowd.class).widthStrategy(WidthStrategy.AUTO_WIDTH).build(dataList);
AttachmentExportUtil.export(workbook, "艺术生信息", response);
}

@GetMapping("/default/continue/example")
public void defaultBuildWithWorkbook(HttpServletResponse response) throws Exception {
List<ArtCrowd> dataList = this.getDataList();
Workbook workbook = DefaultExcelBuilder.of(ArtCrowd.class).autoWidthStrategy(AutoWidthStrategy.AUTO_WIDTH).build(dataList);
Workbook workbook = DefaultExcelBuilder.of(ArtCrowd.class).widthStrategy(WidthStrategy.AUTO_WIDTH).build(dataList);

dataList = this.getDataList();
workbook = DefaultExcelBuilder.of(ArtCrowd.class, workbook).sheetName("sheet2").autoWidthStrategy(AutoWidthStrategy.NO_AUTO).build(dataList);
workbook = DefaultExcelBuilder.of(ArtCrowd.class, workbook).sheetName("sheet2").widthStrategy(WidthStrategy.NO_AUTO).build(dataList);
AttachmentExportUtil.export(workbook, "艺术生信息", response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.liaochong.example.pojo.ArtCrowd;
import com.github.liaochong.myexcel.core.DefaultStreamExcelBuilder;
import com.github.liaochong.myexcel.core.strategy.AutoWidthStrategy;
import com.github.liaochong.myexcel.core.strategy.WidthStrategy;
import com.github.liaochong.myexcel.utils.AttachmentExportUtil;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Controller;
Expand All @@ -24,23 +25,23 @@ public class DefaultStreamExcelBuilderExampleController {

@GetMapping("/default/excel/stream/example")
public void streamBuild(HttpServletResponse response) throws Exception {
DefaultStreamExcelBuilder defaultExcelBuilder = DefaultStreamExcelBuilder.of(ArtCrowd.class)
.autoWidthStrategy(AutoWidthStrategy.CUSTOM_WIDTH)
try (DefaultStreamExcelBuilder defaultExcelBuilder = DefaultStreamExcelBuilder.of(ArtCrowd.class)
.widthStrategy(WidthStrategy.CUSTOM_WIDTH)
.hasStyle()
.threadPool(Executors.newFixedThreadPool(10))
.start();

List<CompletableFuture> futures = new ArrayList<>();
for (int i = 0; i < 100; i++) {
CompletableFuture future = CompletableFuture.runAsync(() -> {
List<ArtCrowd> dataList = this.getDataList();
defaultExcelBuilder.append(dataList);
});
futures.add(future);
.start()) {
List<CompletableFuture> futures = new ArrayList<>();
for (int i = 0; i < 100; i++) {
CompletableFuture future = CompletableFuture.runAsync(() -> {
List<ArtCrowd> dataList = this.getDataList();
defaultExcelBuilder.append(dataList);
});
futures.add(future);
}
futures.forEach(CompletableFuture::join);
Workbook workbook = defaultExcelBuilder.build();
AttachmentExportUtil.export(workbook, "艺术生信息", response);
}
futures.forEach(CompletableFuture::join);
Workbook workbook = defaultExcelBuilder.build();
AttachmentExportUtil.export(workbook, "艺术生信息", response);
}

@GetMapping("/default/excel/stream/continue/example")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public class FreemarkerExcelBuilderExampleController {
*/
@GetMapping("/freemarker/example")
public void build(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new FreemarkerExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder.template("/templates/freemarkerToExcelExample.ftl").build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
try (ExcelBuilder excelBuilder = new FreemarkerExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();
Workbook workbook = excelBuilder.template("/templates/freemarkerToExcelExample.ftl").build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
}
}

/**
Expand All @@ -46,14 +46,15 @@ public void build(HttpServletResponse response) throws IOException {
*/
@GetMapping("/freemarker/defaultStyle/example")
public void buildWithDefaultStyle(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new FreemarkerExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
try (ExcelBuilder excelBuilder = new FreemarkerExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
}
}

/**
Expand All @@ -63,15 +64,16 @@ public void buildWithDefaultStyle(HttpServletResponse response) throws IOExcepti
*/
@GetMapping("/freemarker/xls/example")
public void buildWithXLS(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new FreemarkerExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.workbookType(WorkbookType.XLS)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
try (ExcelBuilder excelBuilder = new FreemarkerExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.workbookType(WorkbookType.XLS)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
}
}

/**
Expand All @@ -81,15 +83,16 @@ public void buildWithXLS(HttpServletResponse response) throws IOException {
*/
@GetMapping("/freemarker/xlsx/example")
public void buildWithXLSX(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new FreemarkerExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.workbookType(WorkbookType.XLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
try (ExcelBuilder excelBuilder = new FreemarkerExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.workbookType(WorkbookType.XLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
}
}

/**
Expand All @@ -99,15 +102,16 @@ public void buildWithXLSX(HttpServletResponse response) throws IOException {
*/
@GetMapping("/freemarker/sxlsx/example")
public void buildWithSXLSX(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new FreemarkerExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.workbookType(WorkbookType.SXLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
try (ExcelBuilder excelBuilder = new FreemarkerExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.workbookType(WorkbookType.SXLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
}
}

/**
Expand All @@ -117,15 +121,16 @@ public void buildWithSXLSX(HttpServletResponse response) throws IOException {
*/
@GetMapping("/freemarker/encrypt/example")
public void buildWithEncrypt(HttpServletResponse response) throws Exception {
ExcelBuilder excelBuilder = new FreemarkerExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.workbookType(WorkbookType.SXLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.encryptExport(workbook, "freemarker_excel", response, "123456");
try (ExcelBuilder excelBuilder = new FreemarkerExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.workbookType(WorkbookType.SXLSX)
.useDefaultStyle()
.build(dataMap);
AttachmentExportUtil.encryptExport(workbook, "freemarker_excel", response, "123456");
}
}

/**
Expand All @@ -135,15 +140,16 @@ public void buildWithEncrypt(HttpServletResponse response) throws Exception {
*/
@GetMapping("/freemarker/autoWidth/example")
public void buildWithAutoWidth(HttpServletResponse response) throws Exception {
ExcelBuilder excelBuilder = new FreemarkerExcelBuilder();
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.useDefaultStyle()
.autoWidthStrategy(AutoWidthStrategy.AUTO_WIDTH)
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
try (ExcelBuilder excelBuilder = new FreemarkerExcelBuilder()) {
Map<String, Object> dataMap = this.getDataMap();

Workbook workbook = excelBuilder
.template("/templates/freemarkerToExcelExample.ftl")
.useDefaultStyle()
.autoWidthStrategy(AutoWidthStrategy.AUTO_WIDTH)
.build(dataMap);
AttachmentExportUtil.export(workbook, "freemarker_excel", response);
}
}

private Map<String, Object> getDataMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class ThymeleafExcelBuilderExampleController {

@GetMapping("/thymeleaf/example")
public void build(HttpServletResponse response) throws IOException {
ExcelBuilder excelBuilder = new ThymeleafExcelBuilder();

Workbook workbook = excelBuilder.template("/templates/demo2.html").build(new HashMap<>());
AttachmentExportUtil.export(workbook, "thymeleaf_excel", response);
try (ExcelBuilder excelBuilder = new ThymeleafExcelBuilder()) {
Workbook workbook = excelBuilder.template("/templates/demo2.html").build(new HashMap<>());
AttachmentExportUtil.export(workbook, "thymeleaf_excel", response);
}
}
}
Loading

0 comments on commit c6eac81

Please sign in to comment.