I need to align a logo and text side by side. But when generating the word document, the text always comes beneath the logo image.I tried the solution pointed out here: http://phpword.codeplex.com/discussions/232684
But it didn't work for me. Here's what i tried (not the solution mentioned above)
$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)));
}
}
and I'm getting this error in
$section->addImage() partCatchable fatal error: Object of class PHPWord_Section_Image could not be converted to string in
Can anyone tell me how I can add image in table cell ?
You should use text run :
$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));
}
}
Link : TextRun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With