Created
July 3, 2013 21:08
-
-
Save matthiaszimmermann/5922844 to your computer and use it in GitHub Desktop.
fill content into a Word template file using the Docx4j support for Eclipse Scout
This file contains hidden or 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
private File runReport(File template) throws ProcessingException { | |
// copy original template file into temp file | |
File tmpFile = IOUtility.createTempFile(IOUtility.getTempFileName(".docx"), IOUtility.getContent(template.getPath())); | |
DocxAdapter docxFile = new DocxAdapter(tmpFile); | |
Map<String, String> variables = new HashMap<String, String>(); | |
// populate doc variables | |
variables.put("Name", "John Doe"); | |
variables.put("Phone", "(123) 456 78 90"); | |
variables.put("CompanyName", "BSI Business Systems Integration AG"); | |
variables.put("Email", "[email protected]"); | |
variables.put("CompanyAddress", "Täfernstrasse 16a, 5405 Baden"); | |
variables.put("InvoiceNo", "No. 2013-007"); | |
variables.put("InvoiceDate", DateUtility.formatDate(new Date())); | |
variables.put("BillingName", "Jane Smith"); | |
variables.put("PayableToName", "John Doe, BSI"); | |
variables.put("SubTotal", "$1,530.00"); | |
variables.put("SalesTax", "$229.50"); | |
variables.put("Shipping", "$250.00"); | |
variables.put("Total", "$2,009.50"); | |
// and content for embedded table | |
Object[][] orderItems = new Object[][]{ | |
new Object[]{"1", "Table", "$800.00", "$800.00"}, | |
new Object[]{"4", "Chair", "$150.00", "$600.00"}, | |
new Object[]{"1", "Assembling", "$130.00", "$130.00"}, | |
}; | |
// fill in doc variables, table content and create output file | |
docxFile.setFields(variables); | |
docxFile.fillTable(1, 1, 0, orderItems); | |
File reportFile = docxFile.save(); | |
return reportFile; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment