PHPWord/samples/Sample_25_TextBox.php

50 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2022-09-16 11:45:45 +02:00
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;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
2016-06-04 20:06:37 +04:00
// New section
$section = $phpWord->addSection();
// In section
2015-01-01 20:41:42 +04:00
$textbox = $section->addTextBox(
2022-09-16 11:45:45 +02:00
[
'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER,
'width' => 400,
'height' => 150,
'borderSize' => 1,
2015-01-01 20:41:42 +04:00
'borderColor' => '#FF0000',
2022-09-16 11:45:45 +02:00
]
2015-01-01 20:41:42 +04:00
);
2016-06-04 20:06:37 +04:00
$textbox->addText('Text box content in section.');
$textbox->addText('Another line.');
2014-05-10 22:04:10 +07:00
$cell = $textbox->addTable()->addRow()->addCell();
2016-06-04 20:06:37 +04:00
$cell->addText('Table inside textbox');
// Inside table
$section->addTextBreak(2);
$cell = $section->addTable()->addRow()->addCell(300);
2022-09-16 11:45:45 +02:00
$textbox = $cell->addTextBox(['borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100]);
2016-06-04 20:06:37 +04:00
$textbox->addText('Textbox inside table');
// Inside header with textrun
$header = $section->addHeader();
2022-09-16 11:45:45 +02:00
$textbox = $header->addTextBox(['width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00']);
$textrun = $textbox->addTextRun();
2016-06-04 20:06:37 +04:00
$textrun->addText('TextBox in header. TextBox can contain a TextRun ');
2022-09-16 11:45:45 +02:00
$textrun->addText('with bold text', ['bold' => true]);
2016-06-04 20:06:37 +04:00
$textrun->addText(', ');
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub');
$textrun->addText(', and image ');
2022-09-16 11:45:45 +02:00
$textrun->addImage('resources/_earth.jpg', ['width' => 18, 'height' => 18]);
2016-06-04 20:06:37 +04:00
$textrun->addText('.');
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}