如何使用包含多个rowpan和colspan的PHPWord制作单词表? [英] How to make the table in word using PHPWord which includes multiple rowspan and colspan?

查看:133
本文介绍了如何使用包含多个rowpan和colspan的PHPWord制作单词表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为自己的学术项目学习PHPWord,并且我还拥有最新的PHPWord库,该库支持rowpan的"vMerge"和colspan的"gridSpan".

I have been learning the PHPWord for my academic project, and I also have the latest PHPWord library which supports "vMerge" for rowspan and "gridSpan" for colspan.

我一直很难创建一种特殊类型的表结构,如下图所示.

I have been finding difficulty in creating one particular type of table structure as shown in the Image below.

问题是如何使'1','2'和'6'的行跨度相同,在这种情况下,该行跨度等于2.

The problem is how to have same rowspan for '1','2' and '6' , in this case it is equal to 2.

任何帮助将不胜感激.

edit-1 我已经成功完成了基本的rowpan和colspan,但是在使用这个复杂的表时却遇到了困难.

edit-1 I have succeeded with basic rowspan and colspan, but I am finding difficulty with this complex table.

推荐答案

示例中有一个示例与您正在执行的操作非常接近:

There is an example in the samples that is quite close to what you are doing: https://github.com/PHPOffice/PHPWord/blob/develop/samples/Sample_09_Tables.php

并对其进行一些修改以实现您的示例:

and modifying that a bit to achieve your example:

$cellRowSpan = array('vMerge' => 'restart');
$cellRowContinue = array('vMerge' => 'continue');
$cellColSpan = array('gridSpan' => 2);

$table->addRow();
$table->addCell(2000, $cellRowSpan)->addText("1");
$table->addCell(2000, $cellRowSpan)->addText("2");
$table->addCell(4000, $cellColSpan)->addText("3");
$table->addCell(2000, $cellRowSpan)->addText("6");

$table->addRow();
$table->addCell(null, $cellRowContinue);
$table->addCell(null, $cellRowContinue);
$table->addCell(2000)->addText("4");
$table->addCell(2000)->addText("5");
$table->addCell(null, $cellRowContinue);

$table->addRow();
$table->addCell(2000);
$table->addCell(2000);
$table->addCell(2000);
$table->addCell(2000);
$table->addCell(2000);

使用0.13.0版本进行了测试(出于某种原因,libreoffice不喜欢带有vMerge的两个相邻单元格的连续定义,并且未按预期显示它们,但是word确实按预期显示了它们)

tested with 0.13.0 version (for some reason libreoffice didn't like the two adjecent cells with vMerge continue definitions and didn't display them as expected, but word did display them nicely as expected)

这篇关于如何使用包含多个rowpan和colspan的PHPWord制作单词表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆