Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.
PHPWord is on Packagist, so installing it on Laravel is as easy as:
composer require phpoffice/phpword
or adding this to your composer.json then running composer install:
"require":{"phpoffice/phpword":"dev-master"}
Once installed, you can use it in your code like this (taken from the documentation):
// 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)'));// Saving the document as HTML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord,'HTML');
$objWriter->save('helloWorld.html');
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.
With PHPWord, you can create OOXML, ODF, or RTF documents dynamically using your PHP 5.3.3+ scripts. Below are some of the things that you can do with PHPWord library:
Set document properties, e.g. title, subject, and creator.
Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering
Create header and footer for each sections
Set default font type, font size, and paragraph style
Use UTF-8 and East Asia fonts/characters
Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text
Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements
Insert titles (headers) and table of contents
Insert text breaks and page breaks
Insert and format images, either local, remote, or as page watermarks
Insert binary OLE Objects such as Excel or Visio
Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan)
Insert list items as bulleted, numbered, or multilevel
PHPWord is installed via Composer. You just need to add dependency on PHPWord into your package.
Example:
{
"require": {
"phpoffice/phpword": "v0.13.*"
}
}
Getting started
The following is a basic usage example of the PHPWord library.
<?phprequire_once'bootstrap.php';// 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('"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('"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('"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('"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. */