2 blue sky 135 blue_sky_135 于 2017.08.28 15:33 提问

php服务器端生成word并在客户端导出相关问题 5C

我参考网上phpword写了一份如题功能的实现,在本地wamp上运行没啥问题,但上传到服务器之后,运行后下载的word文件却为空,求问可能是哪方面的问题。。。
我实现的代码如下所示:
require_once '../PHPWord.php';

// New Word Document
$PHPWord = new PHPWord();
// New portrait section
$section = $PHPWord->createSection();

// Add text elements
$section->addText('Hello World!');
$section->addTextBreak(2);

$section->addText('I am inline styled.', array('name'=>'Verdana', 'color'=>'006699'));
$section->addTextBreak(2);

$PHPWord->addFontStyle('rStyle', array('bold'=>true, 'italic'=>true, 'size'=>16));
$PHPWord->addParagraphStyle('pStyle', array('align'=>'center', 'spaceAfter'=>100));
$section->addText('I am styled by two style definitions.', 'rStyle', 'pStyle');
$section->addText('I have only a paragraph style definition.', null, 'pStyle');

// Save File
$fileName = "word报表".date("YmdHis");
header("Content-type: application/vnd.ms-word");
header("Content-Disposition:attachment;filename=".$fileName.".doc");
header('Cache-Control: max-age=0');
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('php://output');

Csdn user default icon
上传中...
上传图片
插入图片