下载PHPWord放到thinkphp->extend下

具体代码:

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');

更多推荐