This commit is contained in:
parent
2cb124f5b1
commit
fa7f2cdc25
33
README.md
33
README.md
|
|
@ -98,11 +98,15 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
// Adding Text element to the Section having font styled by default...
|
// Adding Text element to the Section having font styled by default...
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars('"Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning." (Albert Einstein)')
|
htmlspecialchars(
|
||||||
|
'"Learn from yesterday, live for today, hope for tomorrow. '
|
||||||
|
. 'The important thing is not to stop questioning." '
|
||||||
|
. '(Albert Einstein)'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note: it is possible to customize font style of the Text element you add in three ways:
|
* Note: it's possible to customize font style of the Text element you add in three ways:
|
||||||
* - inline;
|
* - inline;
|
||||||
* - using named font style (new font style object will be implicitly created);
|
* - using named font style (new font style object will be implicitly created);
|
||||||
* - using explicitly created font style object.
|
* - using explicitly created font style object.
|
||||||
|
|
@ -110,15 +114,26 @@ $section->addText(
|
||||||
|
|
||||||
// Adding Text element having font customized inline...
|
// Adding Text element having font customized inline...
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars('"Great achievement is usually born of great sacrifice, and is never the result of selfishness." (Napoleon Hill)'),
|
htmlspecialchars(
|
||||||
|
'"Great achievement is usually born of great sacrifice, '
|
||||||
|
. 'and is never the result of selfishness." '
|
||||||
|
. '(Napoleon Hill)'
|
||||||
|
),
|
||||||
array('name' => 'Tahoma', 'size' => 10)
|
array('name' => 'Tahoma', 'size' => 10)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Adding Text element having font customized using named font style...
|
// Adding Text element having font customized using named font style...
|
||||||
$fontStyleName = 'oneUserDefinedStyle';
|
$fontStyleName = 'oneUserDefinedStyle';
|
||||||
$phpWord->addFontStyle($fontStyleName, array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true));
|
$phpWord->addFontStyle(
|
||||||
|
$fontStyleName,
|
||||||
|
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
|
||||||
|
);
|
||||||
$section->addText(
|
$section->addText(
|
||||||
htmlspecialchars('"The greatest accomplishment is not in never falling, but in rising again after you fall." (Vince Lombardi)'),
|
htmlspecialchars(
|
||||||
|
'"The greatest accomplishment is not in never falling, '
|
||||||
|
. 'but in rising again after you fall." '
|
||||||
|
. '(Vince Lombardi)'
|
||||||
|
),
|
||||||
$fontStyleName
|
$fontStyleName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -127,7 +142,9 @@ $fontStyle = new \PhpOffice\PhpWord\Style\Font();
|
||||||
$fontStyle->setBold(true);
|
$fontStyle->setBold(true);
|
||||||
$fontStyle->setName('Tahoma');
|
$fontStyle->setName('Tahoma');
|
||||||
$fontStyle->setSize(13);
|
$fontStyle->setSize(13);
|
||||||
$myTextElement = $section->addText(htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)'));
|
$myTextElement = $section->addText(
|
||||||
|
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
|
||||||
|
);
|
||||||
$myTextElement->setFontStyle($fontStyle);
|
$myTextElement->setFontStyle($fontStyle);
|
||||||
|
|
||||||
// Saving the document as OOXML file...
|
// Saving the document as OOXML file...
|
||||||
|
|
@ -142,8 +159,8 @@ $objWriter->save('helloWorld.odt');
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
|
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
|
||||||
$objWriter->save('helloWorld.html');
|
$objWriter->save('helloWorld.html');
|
||||||
|
|
||||||
/* Note: RTF was skipped here, because the format is not XML-based and requires a bit different example. */
|
/* Note: RTF was skipped, because it's not XML-based and requires a different example. */
|
||||||
/* Note: PDF was skipped here, because we use "HTML-to-PDF" approach to create PDF documents. */
|
/* Note: PDF was skipped, because we use "HTML-to-PDF" approach to create PDF documents. */
|
||||||
```
|
```
|
||||||
:warning: Escape any string you pass to OOXML/ODF/HTML document, otherwise it may get broken.
|
:warning: Escape any string you pass to OOXML/ODF/HTML document, otherwise it may get broken.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue