简体   繁体   English

OpenTBS Mail使用PHP合并.docx

[英]OpenTBS Mail merging .docx using PHP

I'm using http://www.tinybutstrong.com/plugins/opentbs/demo/demo.html and having trouble getting it to work. 我正在使用http://www.tinybutstrong.com/plugins/opentbs/demo/demo.html ,但无法正常工作。 My .docx has real word mail merge fields. 我的.docx具有真实的文字邮件合并字段。 I've been trying to understand the documentation, all I can get out of it, is that the PHP demo code, seems to declare $your_name, and then it magically replaces onshow.your_name in the .docx. 我一直在尝试理解文档,但我能从中得到的是,PHP演示代码似乎声明了$ your_name,然后神奇地替换了.docx中的onshow.your_name。

In the first instance, I thought I used MergeBlock with an array of $data. 首先,我以为我将MergeBlock与$ data数组一起使用。 Here's my code so far: 到目前为止,这是我的代码:

  $TBS = new clsTinyButStrong;
  $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

  $template = $_SERVER['DOCUMENT_ROOT'] . '/inc/dd.docx';
  $data = array();
  $data[] = array('ContactName'=>$this->title . ' ' . $this->firstname . ' ' . $this->surname,
                  'Address1'=>$this->address1,
                  'Address2'=>$this->address2,
                  'Address3'=>$this->town,
                  'Address4'=>$this->county,
                  'PostalCode'=>$this->postcode,
                  'Bacsref'=>$this->bb_number,
                  'Account_Name'=>$this->ac_name,
                  'SortCode'=>$this->CorrectedSortCode,
                  'Account_Number'=>$this->CorrectedAccountNumber);
  $ContactName = $this->title . ' ' . $this->firstname . ' ' . $this->surname;
  $TBS->LoadTemplate($template);
  $TBS->MergeBlock('a,b', $data);                
  $file_name = $this->bb_number . ' Direct Debit';
  //$TBS->Plugin(OPENTBS_DEBUG_XML_CURRENT);
  $TBS->Show(OPENTBS_DOWNLOAD, $file_name . '.docx');

The downloaded file hasn't got any of the mail merge fields replaced. 下载的文件没有替换任何邮件合并字段。 From the demo, I can't infer how onshow.your_name, which doesn't look like a real word mail merge field, is replaced? 从演示中,我无法推断出如何替换看起来不像真正的文字邮件合并字段的onshow.your_name? All I see is some error checking code to determine $your_name... 我所看到的是一些错误检查代码,以确定$ your_name ...

OpenTBS is a plug-in for the TinyButStrong template engine (also called TBS) . OpenTBS是TinyButStrong模板引擎(也称为TBS)的插件。 TBS merges text/html/xml contents, while OpenTBS+TBS merges Docx, Xlsx, Pptx, Odt, Ods, ... TBS合并text / html / xml内容,而OpenTBS + TBS合并Docx,Xlsx,Pptx,Odt,Ods,...

This is why, the templating syntax you need is in fact in the TinyButStrong manual. 这就是为什么您所需的模板语法实际上在TinyButStrong手册中。

For example: 例如:

$your_name is merged in the docx with the tag [onload.your_name] because all [onload.*] is an automatic field which will be merged when you call $TBS->Show() , and it will be merged with the corresponding PHP global variables. $your_name与标签[onload.your_name]合并在[onload.your_name]因为所有[onload.*]是一个自动字段,当您调用$TBS->Show()时将被合并,并且它将与相应的PHP合并全局变量。

If in your PHP you did not defined any global variable named $your_name , then TBS will raise an error because it cannot merge [onload.your_name] . 如果在您的PHP中没有定义任何名为$your_name全局变量,则TBS将引发错误,因为它无法合并[onload.your_name]

About MergeBlock(): 关于MergeBlock():

There is the same data/file correspondence. 数据/文件对应相同。 That is: when you code $TBS->MergeBlock('a,b', $data); 那就是:当你编码$TBS->MergeBlock('a,b', $data); TBS will search two blocks named 'a' and 'b' and will merged their fields with $data . TBS将搜索两个名为'a'和'b'的块,并将它们的字段与$data合并。 So you can use [a.ContactName] , [a.Address1] , ... because of the structure of $data . 因此,由于$data的结构,您可以使用[a.ContactName][a.Address1] ...。 But the fields of the Docx template given with the package is no more valid because the structure of $data is not the same. 但是,随包提供的Docx模板的字段不再有效,因为$ data的结构不同。

You can have a look of TBS on-line examples , there is many fields and block syntaxes examples. 您可以看一下TBS在线示例 ,其中有许多字段和块语法示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM