PHPWord/samples/Sample_29_Line.php

65 lines
2.2 KiB
PHP
Raw Normal View History

2014-05-29 16:44:00 +02:00
<?php
include_once 'Sample_Header.php';
// New Word document
2015-01-01 20:41:42 +04:00
echo date('H:i:s'), ' Create new PhpWord object', EOL;
2014-05-29 16:44:00 +02:00
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->addSection();
// Add Line elements
// See Element/Line.php for all options
2015-01-01 20:41:42 +04:00
$section->addText(htmlspecialchars('Horizontal Line (Inline style):'));
2014-05-29 16:44:00 +02:00
$section->addLine(
array(
2015-01-01 20:41:42 +04:00
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
'positioning' => 'absolute',
2014-05-29 16:44:00 +02:00
)
);
2015-01-01 20:41:42 +04:00
$section->addText(htmlspecialchars('Vertical Line (Inline style):'));
2014-05-29 16:44:00 +02:00
$section->addLine(
array(
2015-01-01 20:41:42 +04:00
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1),
'positioning' => 'absolute',
2014-05-29 16:44:00 +02:00
)
);
// Two text break
$section->addTextBreak(1);
2015-01-01 20:41:42 +04:00
$section->addText(htmlspecialchars('Positioned Line (red):'));
2014-05-29 16:44:00 +02:00
$section->addLine(
array(
2015-01-01 20:41:42 +04:00
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1),
'positioning' => 'absolute',
2014-05-29 16:44:00 +02:00
'posHorizontalRel' => 'page',
2015-01-01 20:41:42 +04:00
'posVerticalRel' => 'page',
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(10),
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(8),
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE,
'color' => 'red',
2014-05-29 16:44:00 +02:00
)
);
2015-01-01 20:41:42 +04:00
$section->addText(htmlspecialchars('Horizontal Formatted Line'));
2014-05-29 16:44:00 +02:00
$section->addLine(
array(
2015-01-01 20:41:42 +04:00
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15),
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
2014-05-29 16:44:00 +02:00
'positioning' => 'absolute',
2015-01-01 20:41:42 +04:00
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
'weight' => 10,
2014-05-29 16:44:00 +02:00
)
);
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}