【发布时间】:2019-05-23 19:16:11
【问题描述】:
请谁能告诉我在 phpword 中使用 cloneblock 的语法。
所以我已经在 MySQL 数据库中获得了数据,对于我需要通过 phpword 导入到我的 word doc 中的单行,它工作正常......运行我的查询和搜索并用模板处理器替换。但是,现在我想在我的 word 文档中插入多行。我研究并发现 cloneblock 方法就是答案。但是我无法让它工作......目前我的代码运行但它似乎没有到达第二行。
我实际上没有收到任何错误消息。我的代码执行得很好……但是最后显示的 word 文件没有显示得很好……如果你看到我的代码,我得到了一个回显语句……哪个回显在我的浏览器中正是我想要的“损坏”& “好”,(作为其中一个行数据的示例),但该数据不会像那样被拉入我的 word 文档中......它重复“损坏”,“损坏”。 .
$group_key=1;
do {
//loop to increase my uuid - ($repeatgroup')
$repeatgroup = $id."/"."trailer_repeat_group"."[".$group_key."]";
// query string
$trailer_repeat_grouping = mysqli_query($connect, "SELECT * FROM trailer_repeat_group LEFT JOIN main on trailer_repeat_group.PARENT_KEY = main.metainstanceID WHERE trailer_repeat_group.KEY_id = '$repeatgroup'");
$templateProcessor->cloneBlock('CLONEME', $trailer_count);
while ($row1 = mysqli_fetch_array($trailer_repeat_grouping)) {
//this echo below I am using to test exactly what happends – independent of
//PHPword/templateprocessor
echo $rttc = $row1['right_trailer_tyre_condition'];
//inserting / searching / inserting values
$templateProcessor->setValue("right_trailer_tyre_condition", $rttc);
}
// ending of loop / checking loop
$group_key++;
} while ($group_key <= $trailer_count);
【问题讨论】:
-
专业提示:如果您向我们展示您正在使用的实际代码,您总会得到社区更好的回应
-
示例在 repo 的 Samples 文件夹中:github.com/PHPOffice/PHPWord/blob/develop/samples 和 cloneBlock 示例在这里:github.com/PHPOffice/PHPWord/blob/develop/samples/… 在每条语句上方都有 cmets 记录
-
你读过这个existing Q&A
-
请将您的代码放入您的问题中,该问题不起作用
-
$group_key=1;做 { $repeatgroup = $id."/"."trailer_repeat_group"."[".$group_key."]"; $trailer_repeat_grouping = mysqli_query($connect, "SELECT * FROM trailer_repeat_group LEFT JOIN main on trailer_repeat_group.PARENT_KEY = main.metainstanceID WHERE trail_repeat_group.KEY_id = '$repeatgroup'"); $templateProcessor->cloneBlock('CLONEME', mysqli_num_rows($trailer_repeat_grouping)); $templateProcessor>setValue("right_trailer_tyre_condition",$row['Left_tyre_condition'], 1); $group_key++; } while ($group_key