Categories > OpenTBS with DOCX >

mailmerge 1 template produce 1 docx with multiple pages how?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: sam
Date: 2009-12-24
Time: 00:28

mailmerge 1 template produce 1 docx with multiple pages how?

Hello,
(BTW: To Skrol29 I sent this to your email. Sorry about that I realised this is better posted here)
I am a teacher whose been looking for a web based solution to mail merge with word docx files for our school.
I came across OpenTBS.
I've played around with it and looks like it could do the job.
Most of our uses would be to mail merge a docx file agains multiple students.
e.g
If the word docx looked like this: (this is a very simple example. There would be more fields in a real letter)
--------------------------------
Dear [onshow.firstname] [onshow.surname],
We are happy to offer you a position in our extension class,
please attend a meeting at our school hall this Friday
regards
--------------------------------

I can setup a single letter in OpenTBS, but I cannot do a merge across multiple students and produce a word document with all the students letters 1 per page.
e.g If I needed to send this to 100 students. I would need to create a single docx file of 100 pages. Each letter takes 1 page and each page has the students firstname and surname on it (like the simple example above)
Can I do this in OpenTBS? How is is done?

Many thanks
Sam
By: Skrol29
Date: 2010-01-04
Time: 22:50

Re: mailmerge 1 template produce 1 docx with multiple pages how?

Hi Sam,

I've send a details reply to you. But here is the reply for others which have the same problem.

You may consider this before building your own Microsoft Word template:

TBS tags can be internally split by several special Ms Word tags (OpenXML tags). Unfortunately, Split TBS tags won’t be processed by TBS.  In order to avoid this behavior, you must do as following:
1)    Just go to the Trust  Center  in the Word options, and turn off the setting: "Store random number to improve combine accuracy". See here why.
2)    Each time you enter a new TBS tag, select it and click on the Review ribbon, in the Proofing group, click the Set Language button. In the dialog, make sure the "Do not check
spelling or grammar" box is checked.

The first page is necessary to have a page-break somewhere in the model. Nevertheless, it can be deleted if you have only one paragraph in the first page, and if you  you put the following TBS tag in it:  [onshow;block=w:p;when 0=1]
By: Skrol29
Date: 2010-01-04
Time: 22:51

Re: mailmerge 1 template produce 1 docx with multiple pages how?

This will be mentioned in the OpenTBS manual soon.
By: sam
Date: 2010-01-10
Time: 09:53

Re: mailmerge 1 template produce 1 docx with multiple pages how?

Thanks skrol29.
I've been busy working with opentbs and docx files.
Here is an unusual one I cannot solve.
I have my main group of php files in a folder called "main" and the opetbs files are in main/files/opentbs

When I organise my data and redirect  to a php script in main/files/opentbs like so:
//print "<meta http-equiv=\"refresh\" content=\"0; url=./files/opentbs/sitmerge.php?thedoc=$thedoc&thesql=$thesql\">";

It works perfectly.

But when I grab the contents from the sitmerge.php file and try to call it from within the main folder it does not work.
Here is the code from within the main folder

....
// the working redirect is commented out next line
//print "<meta http-equiv=\"refresh\" content=\"0; url=./files/opentbs/sitmerge.php?thedoc=$thedoc&thesql=$thesql\">";
// #########################################
include_once("../../common.php");
include('tbs_class_php5.php');
include('tbs_plugin_opentbs.php');

$TBS = new clsTinyButStrong; // new instance of TBS
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load OpenTBS plugin


$parth="/srv/schoolwebmergeletters/$owner";
//$TBS->LoadTemplate("$parth/sit_commendation_sample.docx");
$TBS->LoadTemplate("$parth/$thedoc");
//$data = $TBS->MergeBlock('m,*', 'mysql', "SELECT * FROM 2009_rosshill_students order by surname LIMIT 3");

$thesql=urldecode($thesql);
$data = $TBS->MergeBlock('m,*', 'mysql', $thesql);


$TBS->MergeBlock('m', $data);
$file_name = 'students_'.date('Y-m-d_H-i-s').'.docx';
$TBS->Show(OPENTBS_DOWNLOAD+TBS_EXIT, $file_name);
// #########################################

The error occurs even if I do a relative include rather than a chdir:

include('./files/opentbs/tbs_class_php5.php');
include('./files/opentbs/tbs_plugin_opentbs.php');


The problem now is that when I try to merge lots of documents the redirect fails because of a "too many characters in the URI error".
So I have to do it from within the main as a straight query.
Any suggestions?
By: Skrol29
Date: 2010-01-11
Time: 10:05

Re: mailmerge 1 template produce 1 docx with multiple pages how?

Hi Sam,

It is very strange to put the SQL as parameter in the URL. This is a godsend for hackers.

can you give more details about the error you've got ? Why does it not works as expected ?
Have you checked that the path for templates is absolute and not relative?