加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何在phpWord中并排对齐文本和图像?

发布时间:2020-12-13 17:46:30 所属栏目:PHP教程 来源:网络整理
导读:我需要并排对齐徽标和文字.但是当生成word文档时,文本总是位于徽标图像下方.我尝试了这里指出的解决方案: http://phpword.codeplex.com/discussions/232684 但它对我不起作用. 这是我试过的(不是上面提到的解决方案) $section = $PHPWord-createSection();$
我需要并排对齐徽标和文字.但是当生成word文档时,文本总是位于徽标图像下方.我尝试了这里指出的解决方案:
http://phpword.codeplex.com/discussions/232684

但它对我不起作用.
这是我试过的(不是上面提到的解决方案)

$section = $PHPWord->createSection();
$image = $section->addImage('_mars.jpg',array ('width'=>100));
// Add table
$table = $section->addTable(); 
for($r = 1; $r <= 1; $r++) { // Loop through rows
    // Add row
    $table->addRow();
    for($c = 1; $c <= 1; $c++) { // Loop through cells
      // Add Cell
     //I tried adding image in this line.
     $table->addCell(1750)->addText("Row $r,Cell ".
$section->addImage('_mars.jpg',array('width'=>100)));
    }
}

我收到了这个错误

$section->addImage() partCatchable fatal error: Object of class PHPWord_Section_Image could not be converted to string in

谁能告诉我如何在表格单元格中添加图像?

解决方法

你应该使用文本运行:

$section = $PHPWord->createSection();
$image = $section->addImage('_mars.jpg',array ('width'=>100));
// Add table
$table = $section->addTable(); 
for($r = 1; $r <= 1; $r++) { // Loop through rows
    // Add row
    $table->addRow();
    for($c = 1; $c <= 1; $c++) { // Loop through cells
        // Add Cell
        $cell = $table->addCell(1750);
        $textrun = $cell->createTextRun();
        $textrun->addText("Row $r,Cell ");
        $textrun->addImage('_mars.jpg',array('width'=>100));
    }
}

链接:TextRun

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读