Categories > OpenTBS with DOCX >

DOCX with table of contents

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Marcos
Date: 2015-04-07
Time: 16:06

DOCX with table of contents

Good Morning,

I like to know if have any news about table of contents? I found some old topics with no solution about this, anyone found any idea? Thanks!
By: Skrol29
Date: 2015-04-08
Time: 23:58

Re: DOCX with table of contents

There is a an option that can be actived in a DOCX in order to force each calculated field to be recalculated when the DOCX is opened.
But this option also make a message box confirmation when the docs is opened.

See :
https://social.msdn.microsoft.com/Forums/fr-FR/80e59349-d5b3-4629-84d8-58dc3f2c405b/updating-table-of-contents-word-2007?forum=oxmlsdk#43e6b52d-44e8-4c3f-a431-17b87540a656
By: Marcos
Date: 2015-04-30
Time: 16:50

Re: DOCX with table of contents

Nice! Its ok for me dialog confirmation, but how i insert this "<w:updateFields w:val="true" />" via opentbs on my document? is possible or i need change in xml directly? these option could be enabled via word?
By: Skrol29
Date: 2015-05-01
Time: 23:09

Re: DOCX with table of contents

For now you have to change it directly in the DOCX.
Next OpenTBS version will have  feature for editing simple XML values.
By: Marcos
Date: 2015-06-04
Time: 16:25

Re: DOCX with table of contents

Thanks Skrol29 this worked for me!
By: Katy
Date: 2016-07-13
Time: 16:58

Re: DOCX with table of contents

Hi. i don't understand the part "for now you have to change it directly in the docx" Can you explain a little bit more how to do that?  I am fine our users seeing a message box. I just don't want them to be unaware that the table of contents is wrong and publish it without updating. I tried converting the docx to an xml file, editing in <w:updateFields w:val="true" /> in the settings, then opening the xml file. it worked fine the first time and prompted me to update the fields. But it didn't work the next time i opened the xml and i could not save it as a docx file to use as a template for OpenTBS that would prompt me to update the fields. In past versions of Word, we did this with an auto-open macro so when we create a dynamic word document where the page numbers and sections in a table of contents are changed by our application when the user opens the document created, it would automatically update the TOC. But now we cannot have macros in our docx files. Can you tell me if there is a way in OpenTBS where we can write this <w:updateFields w:val="true" /> to the file we are working on so that when the user opens it, it either automatically updates the TOC or it prompts the user offering them the choice to update fields?
By: Skrol29
Date: 2016-07-13
Time: 23:42

Re: DOCX with table of contents

I tried both solution and I ha a bad result with Ms Word 2007 (the document is badly displayed after the message box about refreshing fileds), but ok with Ms Word 2010.

* Method with the « dirty » attribute :

This method is simple but it will work only if there is no « w:dirty » attribute on fields in the document.
$TBS->Source = str_replace('<w:fldChar ', '<w:fldChar w:dirty="true" ', $TBS->Source);

* Method with the <w:updateFields> element :

With OpenTBS version >= 1.9.5
$TBS->PlugIn(OPENTBS_EDIT_ENTITY, 'word/settings.xml', 'w:settings/w:updateFields', 'w:val', 'true', true);
By: Katy
Date: 2016-07-13
Time: 23:44

Re: DOCX with table of contents

THANK YOU!! Trying it tonight and will let you know how i do. How do fields get a "w:dirty" attribute? If i use openTBS to create the docx from my template and i remove sections from it, will they have dirty attribute? I'll find out tonight, fingers crossed :-)
By: Skrol29
Date: 2016-07-13
Time: 23:53

Re: DOCX with table of contents

> How do fields get a "w:dirty" attribute?

I don't know, but I guess it may happens since the attribute exists.
Please not the new code, it is more simple.
By: Katy
Date: 2016-07-14
Time: 04:24

Re: DOCX with table of contents

used the OpenTBS version >=1.9.5 TBS Plugin solution you gave. Works PERFECTLY for my purposes!!! Thank you soooooooo much!