Categories > OpenTBS with DOCX >

Get names of mergefields in docx

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Dorothee
Date: 2015-12-06
Time: 17:47

Get names of mergefields in docx

Hi,
In my web application people can upload and download word documents.
Before downloading, two mergefields in the header are merged with data. That works very well.

Before uploading, I would like to check that the header of the uploaded word document contains the wo mergefields.
Nowbody should upload a word document without the two mergefields.
How can I check that? Is there any method?

Tahnk you very much for a answer.
Dorothee
By: Skrol29
Date: 2015-12-11
Time: 00:30

Re: Get names of mergefields in docx

Hi,

You can simply read the content of the header sub-file.
See command OPENTBS_SELECT_HEADER
http://www.tinybutstrong.com/opentbs.php?doc#commands_for_documents

Since you've selected a sub-file, the content is in property $TBS->Source
By: Dorothee
Date: 2015-12-12
Time: 10:52

Re: Get names of mergefields in docx

Hi
Thank you very much for your answer.

I tried, but unfortunately, $TBS->source does not contain the mergefields from the header.

Here ist my code:

         App::import('Vendor', 'tbs/tbs_class');
         App::import('Vendor', 'tbs/tbs_plugin_opentbs');

         $otbs  = new clsTinyButStrong;
         $otbs->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
         $otbs->LoadTemplate($wohin);
         $ok = $otbs->PlugIn(OPENTBS_SELECT_HEADER);
         $kopf = $otbs->Source;

$wohin is the word document (name and path to it)
$ok is true.

$kopf contains:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n<w:hdr xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16se="http:

What is wrong?

Thank you for giving me an idea.
Dorothee

By: Skrol29
Date: 2015-12-13
Time: 22:48

Re: Get names of mergefields in docx

Hi,

Did you take care, as explained in the documentation, that a DOCX may have several header files.
Thus you have to try other option of the OPENTBS_SELECT_HEADER command to check the good one.
By: Dorothee
Date: 2015-12-14
Time: 09:53

Re: Get names of mergefields in docx

Hi

I found out, that $TBS->source contains the mergefields, even though I can't see them.
Everything works fine and I am very happy now. Thank you very much.

Thank you also for the anser to the forum subject "I cant delete the template after the new file is saved."
Now I can close the document and then delete it.

Dorothee

By: Skrol29
Date: 2015-12-14
Time: 16:02

Re: Get names of mergefields in docx

You're welcome !