2015-07-25 20 views

risposta

11

PHPWord è in Packagist, così l'installazione su laravel è facile come:

composer require phpoffice/phpword 

o l'aggiunta di questo al vostro composer.json poi eseguire composer install:

"require": { 
    "phpoffice/phpword": "dev-master" 
} 

Una volta installato, è possibile usalo nel tuo codice come questo (tratto dal 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'); 
+0

Grazie mille!! – Xela

+0

Questo PHPWord crea documenti doc, docx? ? – kushalbhaktajoshi

+0

Sì, crea file doc e docx. –