#275: Recipe for adding a link within a title

This commit is contained in:
Ivan Lanin 2014-06-12 02:41:49 +07:00
parent f54d9a1eb4
commit e9f8e889f8
2 changed files with 43 additions and 0 deletions

View File

@ -65,3 +65,25 @@ Define a numbering style and title styles, and match the two styles (with ``pSty
$section->addTitle('Heading 1', 1); $section->addTitle('Heading 1', 1);
$section->addTitle('Heading 2', 2); $section->addTitle('Heading 2', 2);
$section->addTitle('Heading 3', 3); $section->addTitle('Heading 3', 3);
Add a link within a title
-------------------------
Apply 'HeadingN' paragraph style to TextRun or Link. Sample code:
.. code-block:: php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->addTitleStyle(1, array('size' => 16, 'bold' => true));
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true));
$phpWord->addFontStyle('Link', array('color' => '0000FF', 'underline' => 'single'));
$section = $phpWord->addSection();
// Textrun
$textrun = $section->addTextRun('Heading1');
$textrun->addText('The ');
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link');
// Link
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');

View File

@ -1017,6 +1017,27 @@ $section->addTitle('Heading 2', 2);
$section->addTitle('Heading 3', 3); $section->addTitle('Heading 3', 3);
``` ```
## Add a link within a title
Apply 'HeadingN' paragraph style to TextRun or Link. Sample code:
```php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->addTitleStyle(1, array('size' => 16, 'bold' => true));
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true));
$phpWord->addFontStyle('Link', array('color' => '0000FF', 'underline' => 'single'));
$section = $phpWord->addSection();
// Textrun
$textrun = $section->addTextRun('Heading1');
$textrun->addText('The ');
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link');
// Link
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');
```
# Frequently asked questions # Frequently asked questions
## Is this the same with PHPWord that I found in CodePlex? ## Is this the same with PHPWord that I found in CodePlex?