4

我目前正在使用 PHPWord 生成我的文档,但我想在文档中添加一条水平线。就像一个


在 HMTL 中。在 word 中,您可以通过输入三个下划线来执行此操作,但我想在生成的文档中使用它。

有人知道有关此功能的更多信息吗?

谢谢!

4

5 回答 5

5

我解压了“.docx”文件,发现最接近的 xml 标签是“w:pBdr”。

<w:pBdr><w:bottom w:val="single" w:sz="6" w:space="0" w:color="auto"/></w:pBdr>

所以,我通过 ParagraphStyle 插入一条水平线。

$section->addText('', [], ['borderBottomSize' => 6]);
于 2018-03-14T09:02:47.170 回答
4

也可以在部分中添加水平线,而不是添加边框:

$section->addLine(['weight' => 1, 'width' => 600, 'height' => 0]);

请注意,宽度以像素为单位,这是此方法的主要缺点。您需要知道页面的宽度(减去边距)以像素为单位。如果您将其设置为较大的数字,则该行将一直延伸到页面的右侧,而忽略页边距。

于 2016-03-08T16:00:35.330 回答
1

您可以尝试使用添加表格和应用边框而不是<hr>使用phpword添加吗

     $styleTable = array('borderSize'=>1, 'borderColor'=>'006699');
     $styleFirstRow = array('borderBottomSize'=>1, 'borderBottomColor'=>'0000FF');
     $this->word->addTableStyle('myOwnTableStyle', $styleTable, $styleFirstRow);
     // Add table
     $table = $section->addTable('myOwnTableStyle');

参考:http ://www.ahowto.net/php/creating-ms-word-document-using-codeigniter-and-phpword

于 2013-11-16T18:13:25.003 回答
1

您可以使用 addLine 方法添加行。

引自:https ://phpword.readthedocs.io/en/latest/elements.html?highlight=line#line

$lineStyle = array('weight' => 1, 'width' => 100, 'height' => 0, 'color' => '38c172');
$section->addLine($lineStyle);

可用的线型属性:

  • 重量。线宽以缇为单位。
  • 颜色。定义描边的颜色。不带 # 标记的十六进制值
  • 短跑。线条类型:dash、rounddot、squaredot、dashdot、longdash、longdashdot、longdashdotdot。
  • 开始箭头。箭头的起始类型:方块、开放、经典、菱形、椭圆形。
  • 结束箭头。箭头的末端类型:方块,开放,经典,菱形,椭圆形。
  • 宽度。以 pt 为单位的线对象宽度。
  • 高度。以 pt 为单位的线对象高度。
  • 翻动。翻转线元素:真,假。
于 2019-06-23T21:33:30.760 回答
0

我认为最接近的<hr>是段落的边框属性:

$phpWord->addParagraphStyle('myBorderStyle', array(
    'borderSize' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(1), 
    'borderColor' => 'FF0000',
    'borderBottomSize' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(4),
    'borderTopColor' => '00FF00'
));

值得注意的:

  • 尺寸以 TWIPS 为单位。
  • 您可以单独设置所有方向(toprightbottomleft)。
  • 您不能设置边框的类型(如dashed)。
于 2017-08-17T07:05:48.823 回答