首页 > 解决方案 > 合并字段不通过 TinyButStrong 合并 word 文档中的数据

问题描述

我正在使用 TinyButStrong 合并 docx 文件中的数据。我有相同的示例数据。为此,我编写了以下代码:

 <?php
 include_once('tbs_class.php'); 
 include_once('../tbs_plugin_opentbs.php');
 if(version_compare(PHP_VERSION,'5.1.0')>=0) {
   if (ini_get('date.timezone')=='') {
     date_default_timezone_set('UTC');
   }
 }

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


   $entityname  = $demodata['entity_name'];

   $x_num = 3152.456;
   $x_pc = 0.2567;
   $x_dt = mktime(13,0,0,2,15,2010);
   $x_bt = true;
   $x_bf = false;
   $x_delete = 1;


   $template = 'draft_response_auto_populate.docx';
   $TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); 

   if (isset($_POST['debug']) && ($_POST['debug']=='current')) $TBS->Plugin(OPENTBS_DEBUG_XML_CURRENT, true); // Display the intented XML of the current sub-file, and exit.
   if (isset($_POST['debug']) && ($_POST['debug']=='info'))    $TBS->Plugin(OPENTBS_DEBUG_INFO, true); // Display information about the document, and exit.
   if (isset($_POST['debug']) && ($_POST['debug']=='show'))    $TBS->Plugin(OPENTBS_DEBUG_XML_SHOW); // Tells TBS to display information when the document is merged. No exit.

    $TBS->MergeField('vs.duedate', $demodata['due_date']);

    $TBS->PlugIn(OPENTBS_DELETE_COMMENTS);


    $save_as = (isset($_POST['save_as']) && (trim($_POST['save_as'])!=='') && ($_SERVER['SERVER_NAME']=='localhost')) ? trim($_POST['save_as']) : '';
    $output_file_name = str_replace('.', '_'.date('Y-m-d').$save_as.'.', $template);

  if($save_as==='') {
$TBS->Show(OPENTBS_DOWNLOAD, $output_file_name); // Also merges all [onshow] automatic fields.
  exit();
 } else {
 $TBS->Show(OPENTBS_FILE, $output_file_name); // Also merges all [onshow] automatic fields.
exit("File [$output_file_name] has been created.");
}

当我下载 word 文档时,它的唯一回复句柄 $entityname = $demodata['entity_name']; 我想替换所有字段。我附上样本 docx:

 Date: [vs.duedate] 
 To, 
 Mr. ………………….,
 The Assistant Commissioner, Audit-I
 Delhi

 Sub:   Request for granting time extension for filing the reply to the notice received in form GST ADT-01bearing file no- [vs.eventnumber] dated 05.11.2020 ('Notice') received on dated [vs.eventdate]
 Ref:   [vs.eventdescription]

 We [vs.entity_name] (hereinafter referred to as “we” or “the Company”), are registered as a regular taxpayer under the Goods and Services (“GST”) Act, bearing GSTIN [vs.registrationno]

对于我使用的替换字段:- $TBS->MergeField('vs.duedate', $demodata['due_date']);

但它没有取代。请帮我。

标签: phpopentbstinybutstrong

解决方案


为了将所有项目与您必须调用$demodata的字段合并[vs.*]

$TBS->MergeField('vs', $demodata);

但随后 item$demodata['due_date']将与字段合并[vs.due_date],而不是[vs.duedate]


推荐阅读