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

问题描述 投票:0回答:1

我对phpword表有问题。

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS90ZEd4UGI1LnBuZyJ9” alt =“表结构”>

我有下表,我想克隆第一行并替换其中的信息。到目前为止,我没有任何进展。我已经使用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"
]

而这个错误Can not clone row, template variable not found or variable contains markup.at TemplateProcessor->cloneRow('${FIRST_NAME}', 2)

如果您给我任何想法,我将如何克隆此行并在其中插入值,我将非常感谢。

laravel invoice phpword phpoffice
1个回答
0
投票

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

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

我正在使用cloneRow('ROW', 2)方法克隆行PhpWord Docs这给了我2个可以使用的ROW副本,并在其中每个副本上添加了#INDEX。这样,我就遍历了它们,并用像这样的实际值替换了[[placeholder foreach ($fields as $key => $value) { $this->wordFile->setValue(strtoupper($key) . '#' . $index, $value); $this->wordFile->setValue('ROW#' . $index, $index); }

KEY变量是字段名,然后将#INDEX连接到它。

克隆行以索引1(#1,#2,#3等...)开始。

© www.soinside.com 2019 - 2024. All rights reserved.