Categories > OpenTBS with DOCX >

merge all avaliable data (body, header and footer) in word docx

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Fen
Date: 2014-03-10
Time: 13:15

merge all avaliable data (body, header and footer) in word docx

Hello all, i've built a system where users can write their own templates, upload them to server and then download them with data.

but, I've encountered a problem when template have header or footer - they simple don't merge!
I've heard that since 1.5.0 "headers and footers are automatically loaded for OpenOffice & MsOffice."
but is there any way to activate this feature?

some basic info about my system:

template could be docx or xlsx

i load TBS with
$this->TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

i load templates via this code:
$path = self::getTemplatesPath() . DS . $this->template; // DS is directory separator
if (file_exists($path))
$this->TBS->loadTemplate($path, OPENTBS_ALREADY_UTF8);

i do all merging logic via 1 block and big custom function:
$this->TBS->MergeField('tbs', '~field', true);
and field function of my plugin takes care about any field it encountered

so, what i want to know:
1) if there are any way to automatically mergeField on headers and footers?
2) if no - how i can detect if header file exist in .docx? (and i need to test if its docx first, right?)
3) assuming i can detect header and process header - how do i do mergeField both header and body in one document?


By: Skrol29
Date: 2014-03-11
Time: 23:53

Re: merge all avaliable data (body, header and footer) in word docx

Hi Fen,

OpenTBS automatically load header and footers but only in order to merge automatic fields ([onload] and [onshow])

If you want to use MergeFields() or MergeBlock() on header or footers then you have to load the correspondig sub-files first.

- "word/header1.xml" and "word/footer1.xml" are for standard headers and footers
- "word/header2.xml" and "word/footer2.xml" are for different headers and footers  for odd numbered pages.
- "word/header3.xml" and "word/foote32.xml" are for different headers and footers  the first page.

You can check if the sub-file exist using:
$ok = $TBS->Plugin(OPENTBS_FILEEXISTS, 'word/header1.xml');

You can load a sub-file using:
$TBS->LoadTemplate('#word/header1.xml');

You can load back the main contents using:
$TBS->PlugIn(OPENTBS_SELECT_MAIN);



By: Fen
Date: 2014-03-12
Time: 00:42

Re: merge all avaliable data (body, header and footer) in word docx

thanks for fast response, all works perfect, assuming "word/foote32.xml" is mistype and really its "word/footer3.xml"