Set Checkbox Values Dynamically

Note
The example reads the shop data described in The Business Layer.

You can set checkbox values to either checked or unchecked in your reports dynamically by taking the following steps:

  1. Add a checkbox content control to your template at a place where you want it to appear in a result document.
  2. By editing content control properties, add a check tag to the title of the checkbox content control using the following syntax.
<<check [conditional_expression]>>

The code will look like following snippet:

from groupdocs.assembly import DataSourceInfo, DocumentAssembler

assembler = DocumentAssembler()
assembler.assemble_document("checkbox.docx", "checkbox-report.docx", DataSourceInfo(True, "conditional_expression"))

The following sample file is used in this example: checkbox.docx

Binary file (DOCX, 10 KB)

Download full output

from groupdocs.assembly import DataSourceInfo, DocumentAssembler

assembler = DocumentAssembler()
assembler.assemble_document("dropdown.docx", "dropdown-report.docx", [
    DataSourceInfo("Harbor Blend whole bean coffee", "choice_one"),
    DataSourceInfo("Coffee", "choice_one_display_name"),
    DataSourceInfo("Cold-pressed olive oil", "choice_two"),
    DataSourceInfo("Olive oil", "choice_two_display_name"),
    DataSourceInfo("Aged harbour cheddar", "choice_three"),
    DataSourceInfo("Cheddar", "choice_three_display_name"),
])

The following sample file is used in this example: dropdown.docx

Binary file (DOCX, 16 KB)

Download full output

from groupdocs.assembly import DataSourceInfo, DocumentAssembler

assembler = DocumentAssembler()
assembler.assemble_document("combobox.docx", "combobox-report.docx", [
    DataSourceInfo("Harbor Blend whole bean coffee", "choice_one"),
    DataSourceInfo("Coffee", "choice_one_display_name"),
    DataSourceInfo("Cold-pressed olive oil", "choice_two"),
    DataSourceInfo("Olive oil", "choice_two_display_name"),
    DataSourceInfo("Aged harbour cheddar", "choice_three"),
    DataSourceInfo("Cheddar", "choice_three_display_name"),
])

The following sample file is used in this example: combobox.docx

Binary file (DOCX, 15 KB)

Download full output

Here, conditional_expression defines a condition upon which the value of the checkbox content control is to be set to checked (or unchecked, if the condition is not met). The conditional expression must return a Boolean value.

While building a report, a conditional expression declared within a check tag is evaluated and the value of its containing checkbox content control is set accordingly. The check tag itself is removed then.

Warning
Dynamic checkbox value setting is available for Word Processing documents only.
Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.