Blogger Information
Blog 8
fans 0
comment 1
visits 10177
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkhphp5.0利用PHPWord导出word
Moments的博客
Original
2712 people have browsed it
  1. 下载PHPWord放到thinkphp->extend下

  2. 具体代码:

            Loader::import('PHPWord.php');

            Loader::import('PHPWord.IOFactory.php');

            Loader::import('PHPWord.Section.php');

            Loader::import('PHPWord.Template.php');

            Loader::import('PHPWord.Writer.Word2007.php');

            $PHPWord = new \PHPWord();

            $list=Db::name('user')->select();

            $section = $PHPWord->createSection();

            $styleTable = array('borderColor'=>'006699','borderSize'=>6,'cellMargin'=>50);  

            $styleFirstRow = array('bgColor'=>'66BBFF'); 

            $PHPWord->addTableStyle('myTable', $styleTable, $styleFirstRow);

            $table = $section->addTable('myTable');

            foreach($list as $key=>$value)

            {

                   $table->addRow(400);

                   $table->addCell(2000)->addText($value['id']); 

                   $table->addCell(2000)->addText($value['emp_no']); 

                   $table->addCell(2000)->addText($value['password']);

                   $table->addCell(2000)->addText($value['name'],iconv('UTF-8', 'GB2312//IGNORE=', $value['name']));

           }

           $objWriter = \PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');

           header("Content-type: application/vnd.ms-word");

           header("Content-Disposition:attachment;filename=testExport.docx");

           header('Cache-Control: max-age=0');

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

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!