thaiall logomy background
phpoffice
my town
blankfield |
phpoffice
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
https://github.com/PHPOffice/PHPWord
https://github.com/PHPOffice/PHPWord/tree/develop/samples
https://buildmedia.readthedocs.org/media/pdf/phpword/latest/phpword.pdf
https://support.microsoft.com/en-us/office/create-forms-that-users-complete-or-print-in-word-040c5cc1-e309-445b-94ac-542f732c8c8b
ติดตั้งด้วยคำสั่ง C:\> composer require phpoffice/phpword
http://marcuscode.com/lang/php/namespaces
https://github.com/PHPOffice/PHPWord/issues/902
https://hotexamples.com/examples/-/PhpOffice%255CPhpWord%255CTemplateProcessor/getVariables/php-phpoffice%255cphpword%255ctemplateprocessor-getvariables-method-examples.html
https://thaiall.com/phpoffice/blankfield.php
*/
require_once 'vendor/autoload.php';
include_once 'phpoffice/PhpWord/PhpWord.php';
include_once 'phpoffice/PhpWord/TemplateProcessor.php';
use TemplateProcessor, Shared\Html, PhpWord;
$getfile1 = new \PhpOffice\PhpWord\TemplateProcessor('blankfield1.docx');
var_dump($getfile1->getVariables());
$getfile2 = new \PhpOffice\PhpWord\TemplateProcessor('blankfield2.docx');
var_dump($getfile2->getVariables());
$getfile3 = new \PhpOffice\PhpWord\TemplateProcessor('blankfield3.docx');
var_dump($getfile3->getVariables());
$getvar = $getfile1->getVariables();
echo 'Number of Variables: ' .count($getvar). '
'; for($i=0; $i<count($getvar); $i++) { echo 'varname [' .$i. ']: ' .$getvar[$i]. '
'; }
phpoffice - phpword - save การสั่ง save file ด้วย phpoffice จะต้องใช้ xmlwriter ที่ php เรียกใช้ ถ้าไม่ถูกติดตั้งไว้ ก็ต้องติดตั้งเพิ่มเติม หากตรวจสอบด้วย phpinfo() แล้วไม่พบ xmlwriter บริการอยู่ ก็จะสั่ง save สร้างแฟ้ม .docx ด้วย phpword ไม่ได้
/*
echo __LINE__ . "\n";
// itinlife/prt_article.php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText("abc");
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$phpWord->setDefaultFontSize(18);
$objWriter->save('blankfield.docx');	
*/
rspsocial
Thaiall.com