PHPWod 生成页眉(和页脚)时出错

问题描述 投票:0回答:1

脚本在以前的手动安装版本中是可以的,所以我升级了php(使用LAMPP) 我收到错误:

致命错误:未捕获错误:在 /opt/lampp/htdocs/snvt/bakteriologie-test-zadanka.php:22 中的 null 上调用成员函数 addTable():22 堆栈跟踪:#0 {main} 抛出在 /opt/lampp 中/htdocs/snvt/bakteriologie-test-zadanka.php 第 22 行

<?php
require_once 'vendor/phpoffice/common/tests/bootstrap.php';
include "connection.php";
require_once "functions.php";


//echo phpinfo();
// Creating the new document...
$filepath = "/opt/lampp/temp/PokusBakteriologie.docx";


$phpWord = new \PhpOffice\PhpWord\PhpWord();

/* Note: any element you append to a document must reside inside of a Section. */


$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
// Add header
$header = $section->createHeader();

$table = $header->addTable();
$styleCell =
[
     'borderTopSize' => 10,
    'borderBottomSize' => 10,
    'align'=>'center'
];
$table->addRow();
$table->addCell(2834,$styleCell)->addImage('images/Logo.jpg', array('width'=>130, 'height'=>40,'align'=>'center'));
$myFontStyle=array('name' => 'ARIAL BLACK', 'size' => 15, 'color' => '1B2232', 'bold' => true,'align'=>'center');
$myFontStyle2=array('name' => 'Times New Roman', 'size' => 12, 'color' => '1B2232', 'bold' => true,'align'=>'center');
$c1=$table->addCell(6190,$styleCell);
$c1->addText('VIVA',$myFontStyle,
                               array('align'=>'center'));
$c1->addText(' 1723/6, 500 02 Hradec Králové' ,$myFontStyle2,
                               array('align'=>'center'));
$c1->addText('tel: (+420)49 553 22 33, 777 553 220' ,$myFontStyle2,
                               array('align'=>'center'));
$c1->addText('http://www.xxxx.cz, email : [email protected]' ,$myFontStyle2,
                               array('align'=>'center'));


///////FOOTER Start//////////////////////////////////////////////////////////

//$section = $phpWord->addSection();
// Add footer
$footer = $section->addFooter();

$table = $footer->addTable();
$styleCellFooter =
[
     'borderTopSize' => 10,
        'align'=>'center'
];
$table->addRow();
$myFontStyleFooter=array('name' => 'ARIAL', 'size' => 9, 'color' => '1B2232', 'bold' => true,'align'=>'left');
$myFontStyle2Footer=array('name' => 'Times New Roman', 'size' => 9, 'color' => '1B2232', 'bold' => false,'align'=>'center');
$c1=$table->addCell(2253,$styleCellFooter);
$c1->addText('Adresa: ',$myFontStyleFooter,
                               array('align'=>'left'));
$c1->addText('Medkova 1723/6' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1->addText('500 02 Hradec Králové' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1->addText('http://www.xxxx.cz' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1=$table->addCell(2253,$styleCellFooter);
$c1->addText('Telefon: ',$myFontStyleFooter,
                               array('align'=>'left'));
$c1->addText('(+420) XXX XXX XXX' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1->addText('(+420) 49 XXX XX XX' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1->addText('[email protected]' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1=$table->addCell(2253,$styleCellFooter);
$c1->addText('IČ/DIČ: ',$myFontStyleFooter,
                               array('align'=>'left'));
$c1->addText('64808XX726' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1->addText('CZXXX' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1->addText('KVL reg.č. 3808' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1=$table->addCell(2253,$styleCellFooter);
$c1->addText('Ordinační hodiny: ',$myFontStyleFooter,
                               array('align'=>'left'));
$c1->addText('Po,Út,Čt,Pá: 8:00-18:00' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1->addText('St: 10:00-18:00' ,$myFontStyle2Footer,
                               array('align'=>'left'));
$c1->addText('So,Ne: 9:00-16:00' ,$myFontStyle2Footer,
                               array('align'=>'left'));



//////////FOOTER End/////////////////////////////////////////////////////////






$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($filepath);


header('Content-disposition: inline');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
ob_clean();
readfile($filepath);
exit();


//exit;

php phpword
1个回答
0
投票

Ouu,必须代替 createHeader - addHeader

© www.soinside.com 2019 - 2024. All rights reserved.