Skip to main content

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.

Jump to: navigation, search

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...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

  1. Open the plugin.xml of your share plugin (e.g. org.example.shared).
  2. Add the plugin org.eclipse.scout.docx4j to the dependencies (with reexport enabled).
  3. For each product file, add the following plugins
    1. org.eclipse.scout.docx4j
    2. org.docx4j
    3. org.apache.xmlgraphics
    4. 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();

Back to the top