Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Scout/HowTo/3.8/Fill document variable fields
< Scout | HowTo | 3.8
Revision as of 11:42, 6 December 2012 by Stephan.merkli.bsi-software.com (Talk | contribs) (New page: This tutorial describes how to set document variable fields and fill tables in a word file by using the docx4j integration in Scout. = Plugin Dependencies = To be able to handle documents...)
This tutorial describes how to set document variable fields and fill tables in a word file by using the docx4j integration in Scout.
Plugin Dependencies
To be able to handle documents both in client and server, the necessary plugins are added as a dependency to the shared plugin of the application.
- Open the plugin.xml of your share plugin (e.g. org.example.shared).
- Add the plugin org.eclipse.scout.docx4j to the dependencies (with reexport enabled).
- For each product file, add the following plugins
- org.eclipse.scout.docx4j
- org.docx4j
- org.apache.xmlgraphics
- com.bsiag.jul.logbridge
Open, modify & store a word document
File file = new File(pathToFile); DocxAdapter docxAdapter = new DocxAdapter(file);
Map<String, String> placeholderValues = new HashMap<String, String>(); placeholderValues.put("Name", "Bart Simpson"); // ...
docxAdapter.setFields(placeholderValues);
Object[][] tableData = new Object[][]{ new Object[]{"1000312", "Bart", "Simpson"}, new Object[]{"1040217", "Homer", "Simpson"}, new Object[]{"1023218", "Ned", "Flanders"}, new Object[]{"8424672", "Charles Montgomery", "Burns"}, };
// fill the first table, start at row 1 (second row), column 0 (first column) docxAdapter.fillTable(0, 1, 0, tableData);
// store changes to file docxAdapter.save();