【问题标题】:How to align text and image side by side in phpWord?如何在phpWord中并排对齐文本和图像?
【发布时间】:2014-01-20 08:47:11
【问题描述】:

我需要并排对齐徽标和文本。但是在生成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 

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

【问题讨论】:

    标签: php phpword


    【解决方案1】:

    你应该使用文本运行:

    $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

    【讨论】:

      【解决方案2】:

      请使用这篇文章,它默认不支持,所以你可以使用本教程创建类似图像的功能 http://www.shotdev.com/php/php-com-word/php-word-add-insert-picture-addpicture/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-07-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-09
        • 2017-03-17
        • 2018-09-29
        相关资源
        最近更新 更多