2014-03-24 14:03:02 -04:00
|
|
|
<?php
|
2014-03-29 22:53:34 +07:00
|
|
|
include_once 'Sample_Header.php';
|
2014-03-24 14:03:02 -04:00
|
|
|
|
2014-03-29 22:53:34 +07:00
|
|
|
// New Word document
|
2015-01-01 20:41:42 +04:00
|
|
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
2014-03-29 22:53:34 +07:00
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
2014-04-02 11:02:56 +07:00
|
|
|
$section = $phpWord->addSection();
|
2014-03-24 14:03:02 -04:00
|
|
|
|
2015-02-06 22:28:31 +04:00
|
|
|
$section->addText(htmlspecialchars('By default, when you insert an image, it adds a textbreak after its content.', ENT_COMPAT, 'UTF-8'));
|
2015-01-01 20:41:42 +04:00
|
|
|
$section->addText(
|
2015-02-06 22:28:31 +04:00
|
|
|
htmlspecialchars('If we want a simple border around an image, we wrap the image inside a table->row->cell', ENT_COMPAT, 'UTF-8')
|
2015-01-01 20:41:42 +04:00
|
|
|
);
|
|
|
|
|
$section->addText(
|
|
|
|
|
htmlspecialchars(
|
|
|
|
|
'On the image with the red border, even if we set the row height to the height of the image, '
|
2015-02-06 22:28:31 +04:00
|
|
|
. 'the textbreak is still there:',
|
|
|
|
|
ENT_COMPAT,
|
|
|
|
|
'UTF-8'
|
2015-01-01 20:41:42 +04:00
|
|
|
)
|
|
|
|
|
);
|
2014-03-24 14:03:02 -04:00
|
|
|
|
2015-01-01 20:41:42 +04:00
|
|
|
$table1 = $section->addTable(array('cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0));
|
2014-03-24 14:03:02 -04:00
|
|
|
$table1->addRow(3750);
|
2015-01-01 20:41:42 +04:00
|
|
|
$cell1 = $table1->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => 'ff0000'));
|
2015-10-10 19:22:19 +04:00
|
|
|
$cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
2014-03-24 14:03:02 -04:00
|
|
|
|
|
|
|
|
$section->addTextBreak();
|
2015-01-01 20:41:42 +04:00
|
|
|
$section->addText(
|
|
|
|
|
htmlspecialchars(
|
2015-02-06 22:28:31 +04:00
|
|
|
"But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:",
|
|
|
|
|
ENT_COMPAT,
|
|
|
|
|
'UTF-8'
|
2015-01-01 20:41:42 +04:00
|
|
|
)
|
|
|
|
|
);
|
2014-03-24 14:03:02 -04:00
|
|
|
|
2015-01-01 20:41:42 +04:00
|
|
|
$table2 = $section->addTable(
|
|
|
|
|
array(
|
|
|
|
|
'cellMargin' => 0,
|
|
|
|
|
'cellMarginRight' => 0,
|
|
|
|
|
'cellMarginBottom' => 0,
|
|
|
|
|
'cellMarginLeft' => 0,
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$table2->addRow(3750, array('exactHeight' => true));
|
|
|
|
|
$cell2 = $table2->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => '00ff00'));
|
2015-10-10 19:22:19 +04:00
|
|
|
$cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
2014-03-24 14:03:02 -04:00
|
|
|
|
|
|
|
|
$section->addTextBreak();
|
2015-01-01 20:41:42 +04:00
|
|
|
$section->addText(
|
2015-02-06 22:28:31 +04:00
|
|
|
htmlspecialchars('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.', ENT_COMPAT, 'UTF-8')
|
2015-01-01 20:41:42 +04:00
|
|
|
);
|
2015-02-06 22:28:31 +04:00
|
|
|
$section->addText(htmlspecialchars('So: $' . "table2->addRow(3750, array('exactHeight'=>true));", ENT_COMPAT, 'UTF-8'));
|
2014-03-24 14:03:02 -04:00
|
|
|
|
|
|
|
|
// Save file
|
2014-04-12 10:12:24 +07:00
|
|
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
|
|
|
|
if (!CLI) {
|
|
|
|
|
include_once 'Sample_Footer.php';
|
2014-03-24 14:03:02 -04:00
|
|
|
}
|