From e9f8e889f8fef4e141d14505e861d7995ad558a3 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Thu, 12 Jun 2014 02:41:49 +0700 Subject: [PATCH] #275: Recipe for adding a link within a title --- docs/recipes.rst | 22 ++++++++++++++++++++++ docs/src/documentation.md | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/docs/recipes.rst b/docs/recipes.rst index d5678a52..1b529d7b 100644 --- a/docs/recipes.rst +++ b/docs/recipes.rst @@ -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 2', 2); $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'); diff --git a/docs/src/documentation.md b/docs/src/documentation.md index 144222c1..49505c7f 100644 --- a/docs/src/documentation.md +++ b/docs/src/documentation.md @@ -1017,6 +1017,27 @@ $section->addTitle('Heading 2', 2); $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 ## Is this the same with PHPWord that I found in CodePlex?