José Quiñones Flores 4564da0130 Added Laravel project and removed sensitive data | 4 лет назад | |
---|---|---|
.. | ||
docs | 4 лет назад | |
samples | 4 лет назад | |
src/PhpWord | 4 лет назад | |
tests | 4 лет назад | |
.gitignore | 4 лет назад | |
.scrutinizer.yml | 4 лет назад | |
.travis.yml | 4 лет назад | |
.travis_shell_after_success.sh | 4 лет назад | |
CHANGELOG.md | 4 лет назад | |
CONTRIBUTING.md | 4 лет назад | |
COPYING | 4 лет назад | |
COPYING.LESSER | 4 лет назад | |
LICENSE | 4 лет назад | |
README.md | 4 лет назад | |
VERSION | 4 лет назад | |
composer.json | 4 лет назад | |
phpmd.xml.dist | 4 лет назад | |
phpunit.xml.dist | 4 лет назад | |
phpword.ini.dist | 4 лет назад |
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft Office Open XML (OOXML or OpenXML), OASIS Open Document Format for Office Applications (OpenDocument or ODF), Rich Text Format (RTF), HTML, and PDF.
PHPWord is an open source project licensed under the terms of LGPL version 3. PHPWord is aimed to be a high quality software product by incorporating continuous integration and unit testing. You can learn more about PHPWord by reading the Developers’ Documentation and the API Documentation.
Read more about PHPWord:
With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
PHPWord requires the following:
It is recommended that you install the PHPWord library through composer. To do so, add
the following lines to your composer.json
.
{
"require": {
"phpoffice/phpword": "dev-master"
}
}
Alternatively, you can download the latest release from the releases page. In this case, you will have to register the autoloader.
require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
The following is a basic usage example of the PHPWord library.
<?php
require_once 'src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();
/* Note: any element you append to a document must reside inside of a Section. */
// Adding an empty Section to the document...
$section = $phpWord->addSection();
// Adding Text element to the Section having font styled by default...
$section->addText(
htmlspecialchars(
'"Learn from yesterday, live for today, hope for tomorrow. '
. 'The important thing is not to stop questioning." '
. '(Albert Einstein)'
)
);
/*
* Note: it's possible to customize font style of the Text element you add in three ways:
* - inline;
* - using named font style (new font style object will be implicitly created);
* - using explicitly created font style object.
*/
// Adding Text element with font customized inline...
$section->addText(
htmlspecialchars(
'"Great achievement is usually born of great sacrifice, '
. 'and is never the result of selfishness." '
. '(Napoleon Hill)'
),
array('name' => 'Tahoma', 'size' => 10)
);
// Adding Text element with font customized using named font style...
$fontStyleName = 'oneUserDefinedStyle';
$phpWord->addFontStyle(
$fontStyleName,
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
);
$section->addText(
htmlspecialchars(
'"The greatest accomplishment is not in never falling, '
. 'but in rising again after you fall." '
. '(Vince Lombardi)'
),
$fontStyleName
);
// Adding Text element with font customized using explicitly created font style object...
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Tahoma');
$fontStyle->setSize(13);
$myTextElement = $section->addText(
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
);
$myTextElement->setFontStyle($fontStyle);
// Saving the document as OOXML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
// Saving the document as ODF file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
$objWriter->save('helloWorld.odt');
// Saving the document as HTML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
$objWriter->save('helloWorld.html');
/* Note: we skip RTF, because it's not XML-based and requires a different example. */
/* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */
:warning: Escape any string you pass to OOXML/ODF/HTML document, otherwise it may get broken.
More examples are provided in the samples folder. You can also read the Developers’ Documentation and the API Documentation for more detail.
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute.