ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-06-12 15:24:59  阅读:684  来源: 互联网

标签:php phpword


我需要并排对齐徽标和文字.但是当生成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

标签:php,phpword
来源: https://codeday.me/bug/20190612/1226572.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有