laravel - PhpWord TemplateProcessor 克隆表行并在其中插入信息

标签 laravel invoice phpword phpoffice

我对 phpword 表有疑问。

Table structure

我有下表,我想克隆第一个表行并替换其中的信息。到目前为止,我没有任何进展。我使用 getVariables() 方法从文档中获取所有变量并循环遍历它们。我检查了该值是否为数组,如果是,则它属于该行。我按以下方式构造了数据

Collection {#971 ▼
  #items: array:12 [▼
    "ticket_id" => array:1 [▼
      0 => 7
      0 => 6
    ]
    "ticket_number" => array:2 [▼
      0 => "157-12313121321"
      1 => null
    ]
    "price_offered_bgn" => array:2 [▼
      0 => 978.0
      1 => 196.0
    ]
    "ticket_is" => array:1 [▼
      0 => "Requested"
    ]
    "departure_date" => array:2 [▼
      0 => "2020-10-20 00:00:00"
      1 => "2020-01-29 00:00:00"
    ]
    "return_date" => array:2 [▼
      0 => "2020-10-29 00:00:00"
      1 => null
    ]
    "company_address" => array:1 [▼
      0 => "ADDRESS"
    ]
    "company_bulstat" => array:1 [▼
      0 => ""
    ]
    "company_dds_number" => array:1 [▼
      0 => "BG 104023232353"
    ]
    "mol" => array:1 [▼
      0 => "Gleichner"
    ]
    "first_name" => array:2 [▼
      0 => "Araceli"
      1 => "Francisca"
    ]
    "last_name" => array:2 [▼
      0 => "Gleichner"
      1 => "Schmitt"
    ]
  ]
}

在我尝试克隆变量并插入值后,我得到了以下结果

array:4 [▼
  0 => "TICKET_NUMBER"
  1 => "FIRST_NAME"
  2 => "LAST_NAME"
  3 => "DEPARTURE_DATE"
]
array:9 [▼
  0 => "FIRST_NAME#1"
  1 => "LAST_NAME#1"
  2 => "DEPARTURE_DATE#1"
  3 => "RETURN_DATE#1"
  4 => "TICKET_NUMBER#2"
  5 => "FIRST_NAME#2"
  6 => "LAST_NAME#2"
  7 => "DEPARTURE_DATE#2"
  8 => "RETURN_DATE#2"
]

还有这个错误 无法克隆行,未找到模板变量或变量包含标记。 在 TemplateProcessor->cloneRow('${FIRST_NAME}', 2)

如果您能告诉我如何克隆该行并在其中插入值,我将不胜感激。

最佳答案

问题解决了。我做了这样的表结构

+-----------+----------------+
| ${row}    | ${Item}        |
|           |                +
|           | ${ItemInfo}    |
+-----------+----------------+
+-----------+----------------+
| ${row#1}  | ${Item}        |
|           |                +
|           | ${ItemInfo}    |
+-----------+----------------+

我正在使用 cloneRow('ROW', 2) 方法克隆行 PhpWord Docs这为我提供了 2 个 ROW 副本,我可以使用它们并在每个副本上添加 #INDEX。这样我循环遍历它们并将 place holder 替换为这样的实际值

 foreach ($fields as $key => $value) {
$this->wordFile->setValue(strtoupper($key) . '#' . $index, $value);
$this->wordFile->setValue('ROW#' . $index, $index);
}

KEY 变量是字段名称,然后我将 #INDEX 连接到它。 克隆的行从索引 1 开始(#1、#2、#3 等等...)。

关于laravel - PhpWord TemplateProcessor 克隆表行并在其中插入信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59857229/

相关文章:

laravel livewire 提交表单后返回空白页

php - 如何为两个用户(教师、学生)创建数据透视表,访问分配给并注册到使用 Laravel 的同一类(class)表

php - 从 Mage_Sales_Model_Order_Invoice 对象获取发票 ID

magento-1.4 - Magento : Create an invoice with invoice number = order number?

php - 比较时间时的 Laravel 问题 - 日期格式

Laravel:在 View 中获取当前路由命名空间(form.blade.php)

php - Laravel - DOMDocument::loadXML(): 开始和结束标签不匹配 - PhpWord 错误

codeigniter - PHPWord_Template 保存到客户端

c++ - 里面有结构的类.. C++

php - 使用phpword将html转换为word