<?php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$table = $section->addTable(array(
'borderColor' => '000000','borderSize' => 6
));
$table->addRow();
//单个cell为1800,合并多个单元格时需要将多个单元格的宽度相加
$cell = $table->addCell(9000);
//colspan的一种方式
$cell->getStyle()->setGridSpan(5);
$cell->addText(123);
$table->addRow();
//vMerge代表垂直合并单元格,gridSpan表示colspan的数量
$cell = $table->addCell(1800,['vMerge' => 'restart','valign' => 'center']);
$cell = $table->addCell(1800,['vMerge' => 'restart','valign' => 'center','gridSpan'=>2]);
// 垂直合并单元格,需要在每一行的指定列都加上vMerge,直到不需要合并的单元格
$cell = $table->addCell(1800,['vMerge' => 'continue']);
$cell = $table->addCell(1800,['vMerge' => 'continue']);
$file = iconv("utf-8", "GBK", '检查报告').'.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");