forked from PHPOffice/PHPWord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample_25_TextBox.php
47 lines (41 loc) · 1.9 KB
/
Sample_25_TextBox.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
// In section
$textbox = $section->addTextBox(
array(
'align' => 'center',
'width' => 400,
'height' => 150,
'borderSize' => 1,
'borderColor' => '#FF0000',
)
);
$textbox->addText(htmlspecialchars('Text box content in section.', ENT_COMPAT, 'UTF-8'));
$textbox->addText(htmlspecialchars('Another line.', ENT_COMPAT, 'UTF-8'));
$cell = $textbox->addTable()->addRow()->addCell();
$cell->addText(htmlspecialchars('Table inside textbox', ENT_COMPAT, 'UTF-8'));
// Inside table
$section->addTextBreak(2);
$cell = $section->addTable()->addRow()->addCell(300);
$textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100));
$textbox->addText(htmlspecialchars('Textbox inside table', ENT_COMPAT, 'UTF-8'));
// Inside header with textrun
$header = $section->addHeader();
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
$textrun = $textbox->addTextRun();
$textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun ', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars('with bold text', ENT_COMPAT, 'UTF-8'), array('bold' => true));
$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8'));
$textrun->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8'));
$textrun->addText(htmlspecialchars(', and image ', ENT_COMPAT, 'UTF-8'));
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
$textrun->addText(htmlspecialchars('.', ENT_COMPAT, 'UTF-8'));
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}