如何填充背景行phpword

时间:2017-12-14 07:40:04

标签: php phpword phpoffice

目前我可以为我想要的每个事件设置背景填充颜色。

如何到达该行的全长,如此图所示

enter image description here

  

问题如何将其转到此图像中的日期编号

enter image description here

代码

repositories {
    ......
    maven {
        url 'https://google.bintray.com/tensorflow'
    }
}

完整代码

$results = $this->get_events_for_export();

foreach ($results as $result) {

    //$date = strtotime($result['event_date']);
    $date = strtotime($result['event_date']);

    $month_group = date('M', $date);
    $year_group = date('Y', $date);

    if (!isset($month_isset[$year_group][$month_group]))
    {
        $month_isset[$year_group][$month_group] = [];
    } else {
        $month_group = '';
    }

    if (!empty($result['bg_color'])) {

        $font = array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW);

        $section->addText($month_group ."\t". date('d', $date) ."\t". date('D', $date) ."\t". htmlentities($result['event_title']), $font, $event_lists);

    } else {

        $section->addText($month_group ."\t". date('d', $date) ."\t". date('D', $date) ."\t". htmlentities($result['event_title']), null, $event_lists);
    }
}

1 个答案:

答案 0 :(得分:1)

addTextRun()之前添加addText()方法:

    $textrun = $section->addTextRun();
    if (!empty($result['bg_color'])) {

        $font = array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW);

        $textrun->addText($month_group ."\t");
        $textrun->addText(date('d', $date) ."\t". date('D', $date) ."\t". htmlentities($result['event_title']), $font, $event_lists);

    } else {

        $textrun->addText($month_group ."\t". date('d', $date) ."\t". date('D', $date) ."\t". htmlentities($result['event_title']), null, $event_lists);
    }