Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel PhpWord TemplateProcessor克隆表行并在其中插入信息_Laravel_Invoice_Phpword_Phpoffice - Fatal编程技术网

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

Laravel PhpWord TemplateProcessor克隆表行并在其中插入信息,laravel,invoice,phpword,phpoffice,Laravel,Invoice,Phpword,Phpoffice,我对phpword表格有意见 我有下表,我想克隆第一个表行并替换其中的信息。到目前为止,我没有任何进展。我使用getVariables方法从文档中获取所有变量并循环它们。我已经检查了该值是否为array,是否为array,它是否属于该行。我以以下方式构建了数据 Collection {#971 ▼ #items: array:12 [▼ "ticket_id" => array:1 [▼ 0 => 7 0 => 6 ] "ti

我对phpword表格有意见

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

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}    |
+-----------+----------------+
 foreach ($fields as $key => $value) {
$this->wordFile->setValue(strtoupper($key) . '#' . $index, $value);
$this->wordFile->setValue('ROW#' . $index, $index);
}
我正在用cloneRow'row',2方法克隆行 这给了我两个我可以使用的行的副本,并在每个副本上添加索引。这样,我循环遍历它们,并用实际值替换占位符,如下所示

+-----------+----------------+
| ${row}    | ${Item}        |
|           |                +
|           | ${ItemInfo}    |
+-----------+----------------+
+-----------+----------------+
| ${row#1}  | ${Item}        |
|           |                +
|           | ${ItemInfo}    |
+-----------+----------------+
 foreach ($fields as $key => $value) {
$this->wordFile->setValue(strtoupper($key) . '#' . $index, $value);
$this->wordFile->setValue('ROW#' . $index, $index);
}
关键变量是字段名,然后我将索引连接到它。 克隆的行以索引1、2、3开始,依此类推