php 从文件某一位置开始写,PHPWord添加文本到指定位置

想导出word文档,将文本添加到文档的指定位置,比如前一段话的后面,而前一段话是循环生成的,该段后面又有循环生成的另一段话,而我想加入的文本不能放在循环里,只能在两次循环输出文本之后添加,这样的话我怎么才能把文本输出到紧接着的第一个循环之后?

例如:

bVxVgj

我想将答案放在问题的后面,而问题和选项都是循环生成的,怎么才能实现将其放在“处分”的后面??

求大神赐教

部分代码:

foreach ($ques['answer'] as $key => $an) {

$textrun1 = $section->createTextRun('rStyle');

if (is_array($an['synopsis'])) {

$textrun1->addText($this->aZ[$key] . ".", 'rStyle');

foreach ($an['synopsis'] as $i) {

if (isset($i['type']) && $i['type'] == "text") {

$textrun1->addText($i['value'], 'rStyle');

}

if (isset($i['type']) && $i['type'] == "img" && file_exists($img = ROOT_DIR . str_replace(ROOT_URL, '', $i['value']))) {

$imageStyle = array(

'width' => $i['width'] == 0 ? 350 : $i['width'],

'height' => $i['height'] == 0 ? 350 : $i['height']

// 'align' => 'center',

);

$textrun1->addImage($img, $imageStyle);

}

}

unset($textrun1);

} else {

$section->addText(strtoupper($this->aZ[$key]) . "." . $an['synopsis'], 'rStyle');

}

if ($an['value']) {

$answer[] = $this->aZ[$key];

}

$section->addTextBreak();

}

//判断是否输出答案

if($withAnswer==1){

$section->addText("(" . implode($answer, ",") . ")", 'rStyle');

$section->addTextBreak();

$answer = array();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值