【问题标题】:phpword addText() align justifyphpword addText() 对齐对齐
【发布时间】:2015-07-14 07:24:43
【问题描述】:

当我使用addText() 时,它可以很好地与align=center 一起使用,无论是左还是右,但是当我尝试使用align=justify 时,脚本可以正常工作,但是当我尝试打开.docx 文件时,它给了我错误和文件没有打开。

如果有人知道解决方案,将不胜感激。

$text = "some text";
$PHPWord->addFontStyle('r2Style', array('bold'=>false, 'italic'=>false, 'size'=>12));
$PHPWord->addParagraphStyle('p2Style', array('align'=>'center', 'spaceAfter'=>100));
$section->addText($text, 'r2Style', 'p2Style');

【问题讨论】:

  • 您使用的是哪个 phpword 版本?上面带有 'align' => 'justify' 的段落样式在 phpword 0.12.0 中似乎可以正常工作(在 Word 和 LibreOffice 中存储和打开结果)。
  • 我在windows上使用相同的0.12.0版本,apache和php。

标签: phpword


【解决方案1】:

尝试将'align'=>'left' 更改为'align'=>'both'

$text = "some text";
$PHPWord->addFontStyle('r2Style', array('bold'=>false, 'italic'=>false, 'size'=>12));
$PHPWord->addParagraphStyle('p2Style', array('align'=>'both', 'spaceAfter'=>100));
$section->addText($text, 'r2Style', 'p2Style');

【讨论】:

    【解决方案2】:

    在 src\PhpWord\SimpleType\Jc.php 您将找到有效对齐选项的列表。 “证明”不是(据我所知也不是)一个有效的选项。

    const START = 'start';
    const CENTER = 'center';
    const END = 'end';
    const BOTH = 'both';
    const MEDIUM_KASHIDA = 'mediumKashida';
    const DISTRIBUTE = 'distribute';
    const NUM_TAB = 'numTab';
    const HIGH_KASHIDA = 'highKashida';
    const LOW_KASHIDA = 'lowKashida';
    const THAI_DISTRIBUTE = 'thaiDistribute';
    

    "distribute" 很接近,但即使最后一行是一个单词,它也会在段落的宽度上展开。我已经成功地将“thaiDistribute”和“lowKashida”作为“align”属性的值。正如您在 Word 中所期望的那样,两者都给出了不错的“证明”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 2017-08-20
      • 1970-01-01
      • 2018-09-29
      • 2020-07-12
      • 2018-08-22
      • 1970-01-01
      相关资源
      最近更新 更多