Word extension for YII (depend on the PHPWord library)
- git clone yii-word from github;
- mkdir a directory (named: yiiword) under protected/extensions;
- Unzip the YiiWord to protected/extensions/yiiword;
- Download the latest version of PHPWord: https://phpword.codeplex.com/;
- Unzip the contents of the folder Classes to a new folder protected/vendor/PHPWord/;
- import this library "application.vendors.PHPWord.PHPWord" to the main.php;
Yii::import('ext.yiiword.YiiWord', true);
Yii::registerAutoloader(array('YiiWord', 'autoload'), true);
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
$section->addText('Hell Wordl!');
//generate download page
$filename = time();
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment;filename="'.$filename.'.docx"');
header('Cache-Control: max-age=0');
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('php://output');
unset($this->objWriter);
exit();