-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add xml() function: insert custom xml nodes from variables
- Loading branch information
Showing
8 changed files
with
176 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import io.github.erdos.stencil.API; | ||
import io.github.erdos.stencil.EvaluatedDocument; | ||
import io.github.erdos.stencil.PreparedTemplate; | ||
import io.github.erdos.stencil.TemplateData; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Main { | ||
|
||
public static void main(String... args) throws IOException { | ||
|
||
// prepare template file | ||
PreparedTemplate template = API.prepare(findFile("template.docx")); | ||
|
||
// read XML content from file | ||
String customXML = new String(Files.readAllBytes(findFile("table.xml").toPath())); | ||
|
||
// assemble template data | ||
Map<String, Object> dataMap = new HashMap<>(); | ||
dataMap.put("customXML", customXML); | ||
TemplateData data = TemplateData.fromMap(dataMap); | ||
|
||
// render template | ||
EvaluatedDocument result = API.render(template, data); | ||
|
||
// write generated document to a file | ||
File output = new File("example-output.docx"); | ||
result.writeToFile(output); | ||
} | ||
|
||
private static File findFile(String name) { | ||
return new File(Main.class.getResource(name).getFile()); | ||
} | ||
} |
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,5 @@ | ||
# Inserting custom OOXML content | ||
|
||
This example shows how to insert custom Office Open XML content in the generated document to create a table. | ||
|
||
See the [Main.java](Main.java) file for usage. |
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,43 @@ | ||
<w:tbl xmlns:w="http:https://schemas.openxmlformats.org/wordprocessingml/2006/main"> | ||
<w:tblPr> | ||
<w:tblStyle w:val="TableGrid"/> | ||
<w:tblW w:w="5000" w:type="pct"/> | ||
</w:tblPr> | ||
<w:tblGrid> | ||
<w:gridCol w:w="2880"/> | ||
<w:gridCol w:w="2880"/> | ||
<w:gridCol w:w="2880"/> | ||
</w:tblGrid> | ||
<w:tr> | ||
<w:tc> | ||
<w:tcPr> | ||
<w:tcW w:w="2880" w:type="dxa"/> | ||
</w:tcPr> | ||
<w:p> | ||
<w:r> | ||
<w:t>First cell</w:t> | ||
</w:r> | ||
</w:p> | ||
</w:tc> | ||
<w:tc> | ||
<w:tcPr> | ||
<w:tcW w:w="2880" w:type="dxa"/> | ||
</w:tcPr> | ||
<w:p> | ||
<w:r> | ||
<w:t>Second cell</w:t> | ||
</w:r> | ||
</w:p> | ||
</w:tc> | ||
<w:tc> | ||
<w:tcPr> | ||
<w:tcW w:w="2880" w:type="dxa"/> | ||
</w:tcPr> | ||
<w:p> | ||
<w:r> | ||
<w:t>Third cell</w:t> | ||
</w:r> | ||
</w:p> | ||
</w:tc> | ||
</w:tr> | ||
</w:tbl> |
Binary file not shown.
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