function outword(){
vendor('PHPWord.PHPWord');
vendor('PHPWord.PHPWord.Shared.Font');
$PHPWord = new \PHPWord();
$section = $PHPWord->createSection();//添加默认页
//定义table样式
$styleTable = array('borderSize'=>6,'borderColor'=>'006699','cellMargin'=>80);
//第一行样式
$styleFirstRow = array('borderBottomSize'=>18,'borderBottomColor'=>'0000FF','bgColor'=>'66BBFF');
//定义列样式
$styleCell = array('valign'=>'center');
//使用addCell的第二个参数来给单元格设置样式
//$styleCellBTLR = array('valign'=>'center', 'textDirection'=>PHPWord_Style_Cell::TEXT_DIR_BTLR);
//为第一行定义字体样式
$fontStyle = array('bold'=>true, 'align'=>'center');
//添加table样式
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
//添加表格table
$table = $section->addTable('myOwnTableStyle');
$PHPWord->setDefaultFontName('仿宋'); // 全局字体
$PHPWord->setDefaultFontSize(16); // 全局字号为3号
//添加行的高度
$table->addRow(900);
//添加列
$table->addCell(1000, $styleCell)->addText('品牌id', $fontStyle);
$table->addCell(2000, $styleCell)->addText('品牌名称', $fontStyle);
$table->addCell(1000, $styleCell)->addText('父类', $fontStyle);
$table->addCell(1000, $styleCell)->addText('状态', $fontStyle);
$table->addCell(2000, $styleCell)->addText('添加时间', $fontStyle);
$table->addCell(4000, $styleCell)->addText('图片', $fontStyle);
//准备数据
$brand = M('Brand');
$where = "status = '1'";
$list = $brand->where($where)->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
//dump($list);exit;
//遍历数据
foreach ($list as $k=>$v){
$table->addRow();
$table->addCell(2000)->addText($v['id']);
$table->addCell(2000)->addText($v['name']);
$table->addCell(2000)->addText($v['pid']);
$table->addCell(2000)->addText($v['status']);
$table->addCell(2000)->addText($v['addtime']);
$table->addCell(2000)->addText($v['logo']);
}
$objWriter = \PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('AdvancedTable.docx');
$fileName = "word报表".date("YmdHis");
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');
}
vendor('PHPWord.PHPWord');
vendor('PHPWord.PHPWord.Shared.Font');
$PHPWord = new \PHPWord();
$section = $PHPWord->createSection();//添加默认页
//定义table样式
$styleTable = array('borderSize'=>6,'borderColor'=>'006699','cellMargin'=>80);
//第一行样式
$styleFirstRow = array('borderBottomSize'=>18,'borderBottomColor'=>'0000FF','bgColor'=>'66BBFF');
//定义列样式
$styleCell = array('valign'=>'center');
//使用addCell的第二个参数来给单元格设置样式
//$styleCellBTLR = array('valign'=>'center', 'textDirection'=>PHPWord_Style_Cell::TEXT_DIR_BTLR);
//为第一行定义字体样式
$fontStyle = array('bold'=>true, 'align'=>'center');
//添加table样式
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
//添加表格table
$table = $section->addTable('myOwnTableStyle');
$PHPWord->setDefaultFontName('仿宋'); // 全局字体
$PHPWord->setDefaultFontSize(16); // 全局字号为3号
//添加行的高度
$table->addRow(900);
//添加列
$table->addCell(1000, $styleCell)->addText('品牌id', $fontStyle);
$table->addCell(2000, $styleCell)->addText('品牌名称', $fontStyle);
$table->addCell(1000, $styleCell)->addText('父类', $fontStyle);
$table->addCell(1000, $styleCell)->addText('状态', $fontStyle);
$table->addCell(2000, $styleCell)->addText('添加时间', $fontStyle);
$table->addCell(4000, $styleCell)->addText('图片', $fontStyle);
//准备数据
$brand = M('Brand');
$where = "status = '1'";
$list = $brand->where($where)->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
//dump($list);exit;
//遍历数据
foreach ($list as $k=>$v){
$table->addRow();
$table->addCell(2000)->addText($v['id']);
$table->addCell(2000)->addText($v['name']);
$table->addCell(2000)->addText($v['pid']);
$table->addCell(2000)->addText($v['status']);
$table->addCell(2000)->addText($v['addtime']);
$table->addCell(2000)->addText($v['logo']);
}
$objWriter = \PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('AdvancedTable.docx');
$fileName = "word报表".date("YmdHis");
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');
}