-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from liaochong/feature/4.2.0
Feature/4.2.0
- Loading branch information
Showing
10 changed files
with
144 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/com/github/liaochong/myexcel/core/TemplateStreamExcelBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2019 liaochong | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.liaochong.myexcel.core; | ||
|
||
import com.github.liaochong.myexcel.core.templatehandler.TemplateHandler; | ||
import org.apache.poi.ss.usermodel.Workbook; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author liaochong | ||
* @version 4.2.0 | ||
*/ | ||
public class TemplateStreamExcelBuilder implements Closeable { | ||
|
||
private DefaultStreamExcelBuilder<Void> defaultStreamExcelBuilder; | ||
|
||
private TemplateStreamExcelBuilder() { | ||
} | ||
|
||
public static TemplateStreamExcelBuilder of(Class<? extends TemplateHandler> templateHandlerClass) { | ||
TemplateStreamExcelBuilder templateStreamExcelBuilder = new TemplateStreamExcelBuilder(); | ||
templateStreamExcelBuilder.defaultStreamExcelBuilder = DefaultStreamExcelBuilder.of(Void.class) | ||
.templateHandler(templateHandlerClass) | ||
.start(); | ||
return templateStreamExcelBuilder; | ||
} | ||
|
||
public void append(String templateFilePath, Map<String, Object> renderData) { | ||
defaultStreamExcelBuilder.append(templateFilePath, renderData); | ||
} | ||
|
||
public void append(String templateDir, String templateFileName, Map<String, Object> renderData) { | ||
defaultStreamExcelBuilder.append(templateDir, templateFileName, renderData); | ||
} | ||
|
||
public Workbook build() { | ||
return defaultStreamExcelBuilder.build(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
defaultStreamExcelBuilder.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/test/java/com/github/liaochong/myexcel/core/TemplateStreamExcelBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.github.liaochong.myexcel.core; | ||
|
||
import com.github.liaochong.myexcel.core.templatehandler.ThymeleafTemplateHandler; | ||
import com.github.liaochong.myexcel.utils.FileExportUtil; | ||
import org.apache.poi.ss.usermodel.Workbook; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
|
||
/** | ||
* @author liaochong | ||
* @version 1.0 | ||
*/ | ||
class TemplateStreamExcelBuilderTest extends BasicTest { | ||
|
||
@Test | ||
public void test() throws Exception { | ||
TemplateStreamExcelBuilder templateStreamExcelBuilder = TemplateStreamExcelBuilder.of(ThymeleafTemplateHandler.class); | ||
templateStreamExcelBuilder.append("/templates/thymeleafToExcelExample.html", Collections.emptyMap()); | ||
Workbook workbook = templateStreamExcelBuilder.build(); | ||
FileExportUtil.export(workbook, new File(TEST_OUTPUT_DIR + "template_stream_thymeleaf_build.xlsx")); | ||
} | ||
|
||
} |