0

我想从输出 PHP_WORD 中获取 [underline:PhpOffice\PhpWord\Style\Font:private] 的值,我不知道如何,请告诉我如何。感谢。(对不起我的英语)

[0] => PhpOffice\PhpWord\Element\Text Object
(
    [text:protected] => C
    [fontStyle:protected] => PhpOffice\PhpWord\Style\Font Object
        (
            [aliases:protected] => Array
                (
                    [line-height] => lineHeight
                    [letter-spacing] => spacing
                )

            [type:PhpOffice\PhpWord\Style\Font:private] => text
            [name:PhpOffice\PhpWord\Style\Font:private] => Tahoma
            [hint:PhpOffice\PhpWord\Style\Font:private] => 
            [size:PhpOffice\PhpWord\Style\Font:private] => 12
            [color:PhpOffice\PhpWord\Style\Font:private] => 
            [bold:PhpOffice\PhpWord\Style\Font:private] => 
            [italic:PhpOffice\PhpWord\Style\Font:private] => 
            [underline:PhpOffice\PhpWord\Style\Font:private] => single
            [superScript:PhpOffice\PhpWord\Style\Font:private] => 
            [subScript:PhpOffice\PhpWord\Style\Font:private] => 
            [strikethrough:PhpOffice\PhpWord\Style\Font:private] => 
            [doubleStrikethrough:PhpOffice\PhpWord\Style\Font:private] => 
            [smallCaps:PhpOffice\PhpWord\Style\Font:private] => 
            [allCaps:PhpOffice\PhpWord\Style\Font:private] => 
            [fgColor:PhpOffice\PhpWord\Style\Font:private] => 
            [scale:PhpOffice\PhpWord\Style\Font:private] => 
            [spacing:PhpOffice\PhpWord\Style\Font:private] => 
            [kerning:PhpOffice\PhpWord\Style\Font:private] => 
            [paragraph:PhpOffice\PhpWord\Style\Font:private] => PhpOffice\PhpWord\Style\Paragraph Object

完整数据在这里:https ://pastebin.com/raw/prfejCAup

4

1 回答 1

0

\PhpOffice\PhpWord\Element\Text有一种getFontStyle()访问底层字体样式的方法。

参考\PhpOffice\PhpWord\Style\Font,该方法getUnderline()将返回您尝试获取的下划线样式的值。

因此,要获得您所追求的,请尝试:

$underline = $elements[0]->getFontStyle()->getUnderline(); // 'single'
于 2019-10-06T20:35:24.133 回答