Page 1 of 1

Listbox as condition for other text?

PostPosted: Fri Sep 05, 2014 12:25 am
by baretomas
I am looking for a way to hide/show text in a Word document based on a choice in a dropdown list. I want to do this without using macros.

So I stumbled across this OpenDope solution for Word. But after testing out the addins and trying to understand the documentation, and haven't gotten much to work yet, I'm still not sure if this fits the bill.

Can anyone here answer this?
- Is it possible to hide/show text based on a selection in a Content Control Drop Down list using the OpenDope addin?
- Will this funcitonality still work on a Word installation *without* the OpenDope Addin installed?
- Can all this be achieved without using macros?

Thanks,
Tomas

Re: Listbox as condition for other text?

PostPosted: Fri Sep 05, 2014 11:32 am
by jason
Do you envisage a user making the selection in the list box?

If yes, then this isn't the solution you are looking for. OpenDoPE is for updating the docx programmatically, based on data contained in an XML file.

The programmatic update typically happens outside Word, in Java, so no macros are required.

The OpenDoPE add-in is for authoring the docx in the first place; it is not required at runtime (where everything happens outside Word)

Re: Listbox as condition for other text?

PostPosted: Fri Sep 05, 2014 6:55 pm
by baretomas
Yes.

The user would select his location, and the text relevant for him would show up, and the non-relevant hidden.

I understand, and thanks for your answer.

I thought it would be possible to get the value in the dropdown, compare it to some value in a content control (dropval = "test") and bind that control to an xml node. And then bind that node again (which would be a boolean value now) to a condition that surrounds another (or several) text content control(s). I guess that's a no :)

I did get this working by using IF Fields, with conditions based on the value in the dropdown, but Word doesn't update the fields without user interaction, or macros, so back to square one. :D
I guess I have to use macros for now.

Re: Listbox as condition for other text?

PostPosted: Fri Sep 05, 2014 8:02 pm
by jason
Well, forgetting about OpenDoPE for the moment, http://webapp.docx4java.org/OnlineDemo/ ... nding.html says that you can bind a dropDownList or a comboBox to your XML part.

http://webapp.docx4java.org/OnlineDemo/ ... tem_1.html says

Consider the following combo box structured document tag:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<w:sdt>
  <w:sdtPr>
    <w:comboBox>
      <w:listItem w:displayText="Zero" w:value="0"/>
      <w:listItem w:displayText="One" w:value="1"/>
    </w:comboBox>
  </w:sdtPr>
  …
</w:sdt>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


The value attribute for the first entry is 0 and the second is 1, therefore, these values will be used to determine the display text if the parent structured document tag is mapped to custom XML data in a custom XML data part.

So that only means you can replace your dropDownList/comboBox in situ with the w:displayText, not with the actual value of the XML element.

So that means the 2013 (i think it was 2013) extensions which let you bind rich text, don't get you any further?

I don't think of this as a "condition" as such, since it is limited by the selection in that one dropDownList/comboBox.

By the way I did write a basic VBA implementation of OpenDoPE evaluation ie evaluating conditions; let me take a look at it again to see whether it matches your interactive use case.

Re: Listbox as condition for other text?

PostPosted: Tue Sep 09, 2014 6:57 pm
by baretomas
Thanks again.

I'm not sure if I understand all of it, though.

I think it would work fine with the displayText as well in my situation.
It's prett simple:
I have 7 companies I am writing a common business procedure for. There are, however, slight differences to each company's procedure. Instead of writing a document for each company, I want to add sections which hide when they arte not relevant.
I thought of having the company name in the dropdown, so the user can pick his respective workplace and get the proper procedure.

From the OpenDope website:

That XPath expression could point to a text node containing the text 'true', or it could be a boolean, for example:

/invoice/total > 1000


Couldn't that XPath point to a text node that contains the selection text from the dropdown and replace the 1000 with a company name? Of course changing > to = too... :)

Re: Listbox as condition for other text?

PostPosted: Tue Sep 09, 2014 7:09 pm
by jason
baretomas wrote:Couldn't that XPath point to a text node that contains the selection text from the dropdown and replace the 1000 with a company name? Of


OpenDoPE conditions are powerful/flexible, but when you introduce those, you're in the world of generating your docx outside Word (ie with docx4j), or using a macro inside Word.

Re: Listbox as condition for other text?

PostPosted: Tue Sep 09, 2014 11:04 pm
by baretomas
I understand.

Thanks again!