thaiall logomy background
phpoffice
my town
blankfield |
phpoffice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
ติดตั้งด้วยคำสั่ง C:\> composer require phpoffice/phpword
*/
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). '<br>';
for($i=0; $i<count($getvar); $i++) {
    echo 'varname [' .$i. ']: ' .$getvar[$i]. '<br>';
}
phpoffice - phpword - save การสั่ง save file ด้วย phpoffice จะต้องใช้ xmlwriter ที่ php เรียกใช้ ถ้าไม่ถูกติดตั้งไว้ ก็ต้องติดตั้งเพิ่มเติม หากตรวจสอบด้วย phpinfo() แล้วไม่พบ xmlwriter บริการอยู่ ก็จะสั่ง save สร้างแฟ้ม .docx ด้วย phpword ไม่ได้
1
2
3
4
5
6
7
8
9
10
/*
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
ใช้เวลาโหลดเว็บเพจ = 296 มิลลิวินาที สูง = 918 จุด กว้าง = 1264 จุด
Thaiall.com