您可以通过创建嵌套表来实现这一点。
第 1 步:添加一个父表,其中包含一行两列(单元格)
//Create a section
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section_1 = $phpWord->addSection();
//Define your parent table styles
$parent_table_styles = array('valign' => 'center', 'cellMarginRight' => 200);
$phpWord->addTableStyle('parent_table_styles', $parent_table_styles);
//Add a parent table
$parent_table = $section_1->addTable('parent_table_styles');
//Add a row to the parent table
$parent_table_row_1 = $parent_table->addRow();
//Add a cell to that parent table row
$parent_table_row_1_cell_1 = $parent_table_row_1->addCell();
//Add another cell to that parent table row
$parent_table_row_1_cell_2 = $parent_table_row_1->addCell();
第 2 步: 在父表格单元格中添加子表格(嵌套表格)
//Define your child table and child table cell styles
$child_table_styles = array('valign' => 'center', 'borderSize' => 6, 'borderColor' => '999999');
$phpWord->addTableStyle('child_table_styles', $child_table_styles);
$child_table_cell_styles = array('valign' => 'center');
$phpWord->addTableStyle('child_table_cell_styles', $child_table_cell_styles);
//Add your first child table inside 'cell_1' of the parent table row
$child_table_1 = $parent_table_row_1_cell_1->addTable('style_child_table');
$child_table_1->addRow(200);
$child_table_1->addCell(1200, $child_table_cell_styles)->addText("Col 1");
$child_table_1->addCell(1200, $child_table_cell_styles)->addText("Col 2");
$child_table_1->addRow(200);
$child_table_1->addCell(1200, $child_table_cell_styles)->addText("Col 1");
$child_table_1->addCell(1200, $child_table_cell_styles)->addText("Col 2");
//Add your second child table inside 'cell_2' of the parent table row
$child_table_2 = $parent_table_row_1_cell_2->addTable('style_child_table');
$child_table_2->addRow(200);
$child_table_2->addCell(1200, $child_table_cell_styles)->addText("Col 1");
$child_table_2->addCell(1200, $child_table_cell_styles)->addText("Col 2");
$child_table_2->addRow(200);
$child_table_2->addCell(1200, $child_table_cell_styles)->addText("Col 1");
$child_table_2->addCell(1200, $child_table_cell_styles)->addText("Col 2");