柚子快报邀请码778899分享:php生成word文档

http://yzkb.51969.com/

php生成word文档

/**

* @title phpword样式

*/

public function phpWord1($g)

{

$twips = 20; //单位 1磅 == 20缇

$row = 15.6*$twips; //一行等于15.6磅

$pound_6 = 6*$twips; //6磅

$pound_26 = 26*$twips; //26磅

$firstLine = 0.8;

// 实例化

$phpWord = new \PhpOffice\PhpWord\PhpWord();

//添加默认页面(布局默认页面方向和页边距):

$section = $phpWord->addSection();

//设置字体以及大小

$phpWord->setDefaultFontName('宋体');

$phpWord->setDefaultFontSize(14);

//添加样式

$titleFontStyle = [];

$paragraphStyle = [];

//标题样式

$firstFontStyle = ['size'=>16,'name'=>'黑体'];

$firstParagraphStyle = ['spaceBefore'=>$row,'spaceAfter'=>$pound_6];

$secondFontStyle = ['size'=>15,'name'=>'黑体'];

$secondParagraphStyle = ['spaceBefore'=>$pound_6,'spaceAfter'=>$pound_6];

$thirdFontStyle = ['size'=>14,'name'=>'黑体','bold'=>true];

$zwParagraphStyle = ['indent'=>$firstLine];

// $thirdParagraphStyle = ['spaceBefore'=>$pound_6,'spaceAfter'=>$pound_6];

$section->addText('一、标题',$firstFontStyle,$firstParagraphStyle);

$section->addText('1.主标题',$secondFontStyle,$secondParagraphStyle);

$section->addText($g['main_title'],null,$zwParagraphStyle);//正文

$section->addText('2.副标题',$secondFontStyle,$secondParagraphStyle);

$section->addText($g['noun_title'],null,$zwParagraphStyle);//正文

$section->addText('3.项目基本信息',$secondFontStyle,$secondParagraphStyle);

$section->addText($g['basic_info'],null,$zwParagraphStyle);//正文

$section->addText('二、项目概述',$firstFontStyle,$firstParagraphStyle);

$section->addText($g['overview'],null,$zwParagraphStyle);//正文

$section->addText('三、项目技术和优势详解',$firstFontStyle,$firstParagraphStyle);

$section->addText('1.项目技术和服务',$secondFontStyle,$secondParagraphStyle);

$section->addText('(1)项目依据的技术',$thirdFontStyle,$zwParagraphStyle);

$section->addText($g['position'],null,$zwParagraphStyle);//正文

$section->addText('(2)项目产品或服务',$thirdFontStyle,$zwParagraphStyle);

$section->addText($g['distribution'],null,$zwParagraphStyle);//正文

$file = 'C.docx';

header("Content-Description: File Transfer");

header('Content-Disposition: attachment; filename="' . $file . '"');

header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');

header('Content-Transfer-Encoding: binary');

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Expires: 0');

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');

$xmlWriter->save("php://output");

exit;

}

柚子快报邀请码778899分享:php生成word文档

http://yzkb.51969.com/

推荐阅读

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。