phpword

 1 <?php
 9 Yii::import("ext.PhpWord.*");
10 class TestController extends Controller
11 {
12     /**
13      * 主页
14      */
15     public function actionHome()
16     {
17         include_once 'Autoloader.php';
18         \PhpOffice\PhpWord\Autoloader::register();
19         $phpWord = new \PhpOffice\PhpWord\PhpWord();
20     $section = $phpWord->addSection();
21     // Adding Text element to the Section having font styled by default...
22     $section->addText(
23       htmlspecialchars(
24           '"Learn from yesterday, live for today, hope for tomorrow. '
25             . 'The important thing is not to stop questioning." '
26             . '(Albert Einstein)'
27         )
28     );
29 
30     $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
31     $objWriter->save('./phpword/helloWorld2.docx');34     }
35 }

 

posted @ 2015-03-28 15:09  jami918  阅读(259)  评论(0)    收藏  举报