Skip to content

Commit e9f8e88

Browse files
committed
PHPOffice#275: Recipe for adding a link within a title
1 parent f54d9a1 commit e9f8e88

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

docs/recipes.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,25 @@ Define a numbering style and title styles, and match the two styles (with ``pSty
6565
$section->addTitle('Heading 1', 1);
6666
$section->addTitle('Heading 2', 2);
6767
$section->addTitle('Heading 3', 3);
68+
69+
Add a link within a title
70+
-------------------------
71+
72+
Apply 'HeadingN' paragraph style to TextRun or Link. Sample code:
73+
74+
.. code-block:: php
75+
76+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
77+
$phpWord->addTitleStyle(1, array('size' => 16, 'bold' => true));
78+
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true));
79+
$phpWord->addFontStyle('Link', array('color' => '0000FF', 'underline' => 'single'));
80+
81+
$section = $phpWord->addSection();
82+
83+
// Textrun
84+
$textrun = $section->addTextRun('Heading1');
85+
$textrun->addText('The ');
86+
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link');
87+
88+
// Link
89+
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');

docs/src/documentation.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,27 @@ $section->addTitle('Heading 2', 2);
10171017
$section->addTitle('Heading 3', 3);
10181018
```
10191019

1020+
## Add a link within a title
1021+
1022+
Apply 'HeadingN' paragraph style to TextRun or Link. Sample code:
1023+
1024+
```php
1025+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
1026+
$phpWord->addTitleStyle(1, array('size' => 16, 'bold' => true));
1027+
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true));
1028+
$phpWord->addFontStyle('Link', array('color' => '0000FF', 'underline' => 'single'));
1029+
1030+
$section = $phpWord->addSection();
1031+
1032+
// Textrun
1033+
$textrun = $section->addTextRun('Heading1');
1034+
$textrun->addText('The ');
1035+
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link');
1036+
1037+
// Link
1038+
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');
1039+
```
1040+
10201041
# Frequently asked questions
10211042

10221043
## Is this the same with PHPWord that I found in CodePlex?

0 commit comments

Comments
 (0)