当前位置:网站首页>Laravel uses phpword to generate word documents

Laravel uses phpword to generate word documents

2022-06-26 04:22:00 Scholar and

One : install phpword Class library

composer require phpoffice/phpword

Report errors :(composer require Out of installation memory )

Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes)

Re install :( Temporarily allocate unlimited memory for installation )

php -d memory_limit=-1 composer require phpoffice/phpword

Two : introduce phpword class

use PhpOffice\PhpWord\PhpWord;

3、 ... and : establish word file

$phpWord     = new PhpWord();
$phpWord->setDefaultFontName(' In black ');// Set the font 
$phpWord->setDefaultFontSize(13);// Font size 
$section    = $phpWord->addSection();// Create a blank page 
$section->addTitle(' This is a title, ');
$section->addTextBreak();// Blank line 
$section->addText(' Inline text ');
$writer = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');// Generate the file 
$files  = 'test.docx';
$writer->save($files);
$name   = basename($files);// file name (test)
return response()->download($files, $name, $headers = ['Content-Type'=>'application/zip;charset=utf-8']);// Download the file 
原网站

版权声明
本文为[Scholar and]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180533333771.html