PHPWord 서버에 저장하지 않고 다운로드시키기

PHPWord 서버에 저장하지 않고 다운로드시키기

1 사전 작업

2 phpword1.php 작성

[root@zetawiki ~]# cd /var/www/html
[root@zetawiki html]# mkdir -p ex/phpword
[root@zetawiki html]# cd ex/phpword
[root@zetawiki phpword]# pwd
/var/www/html/ex/phpword
[root@zetawiki phpword]# vi phpword1.php
<?php
require_once 'PHPWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
 
$phpWord = new \PhpOffice\PhpWord\PhpWord();
 
$section = $phpWord->addSection();
$section->addText( htmlspecialchars(
		'"Hello" World. 안녕 친구들'
	));
$section->addText( htmlspecialchars(
		'"Lorem Ipsum 로렘 입숨'
	),
		array('name' => 'Tahoma', 'size' => 10)
	);
 
$writer = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="phpword1.xlsx"');
header('Cache-Control: max-age=0');

$writer->save('php://output');

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}