【问题标题】:OpenTBS Mail merging .docx using PHPOpenTBS 邮件使用 PHP 合并 .docx
【发布时间】:2012-03-27 14:36:37
【问题描述】:

我正在使用http://www.tinybutstrong.com/plugins/opentbs/demo/demo.html,但无法正常工作。我的 .docx 有真正的 word 邮件合并字段。我一直在尝试理解文档,我能从中得到的只是 PHP 演示代码,似乎声明了 $your_name,然后它神奇地替换了 .docx 中的 onshow.your_name。

在第一个例子中,我以为我使用了带有 $data 数组的 MergeBlock。到目前为止,这是我的代码:

  $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');

下载的文件没有替换任何邮件合并字段。从演示中,我无法推断出看起来不像真正的单词邮件合并字段的 onshow.your_name 是如何被替换的?我所看到的只是一些错误检查代码来确定 $your_name...

【问题讨论】:

  • 抱歉,下载的文件没有替换任何邮件合并字段。从演示中,我无法推断出看起来不像真正的单词邮件合并字段的 onshow.your_name 是如何被替换的?我所看到的只是一些错误检查代码来确定 $your_name...

标签: php ms-word docx tinybutstrong opentbs


【解决方案1】:

OpenTBS 是TinyButStrong 模板引擎(也称为 TBS)的插件。 TBS合并text/html/xml内容,而OpenTBS+TBS合并Docx, Xlsx, Pptx, Odt, Ods, ...

这就是为什么,您需要的模板语法实际上在 TinyButStrong 手册中。

例如:

$your_name在docx中与标签[onload.your_name]合并,因为所有[onload.*]是一个自动字段,当你调用$TBS->Show()时会被合并,它会与相应的PHP全局变量合并。

如果在您的 PHP 中您没有定义任何名为 $your_name 的全局变量,那么 TBS 将引发错误,因为它无法合并 [onload.your_name]

关于 MergeBlock():

存在相同的数据/文件对应关系。即:当您编码$TBS->MergeBlock('a,b', $data); 时,TBS 将搜索名为“a”和“b”的两个块,并将它们的字段与$data 合并。所以你可以使用[a.ContactName], [a.Address1], ...因为$data的结构。但是包中给出的Docx模板的字段不再有效,因为$data的结构不一样。

你可以看看TBS on-line examples,有很多字段和块语法的例子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多