0

我想在表格单元格中设置一个超链接:

/* ADD TABLE ROW */
    foreach ($entries as $entry) {
        $row = $tableShape->createRow();
        $row->getFill()->setFillType(Fill::FILL_SOLID)
                ->setStartColor(new Color('FFFFFFFF'))
                ->setEndColor(new Color('FFFFFFFF'));
        $row->nextCell()->createTextRun(date_format($entry->getDate(), "d.m.Y"));
        $row->nextCell()->createTextRun($entry->getTonality()->getName());
        $row->nextCell()->createTextRun($entry->getAccountname());
        $row->nextCell()->createTextRun($entry->getContent());
        $row->nextCell()->createTextRun($entry->getFollower());
        $row->nextCell()->createTextRun($entry->getLink());
    }

此代码不起作用:

$row->nextCell()->createTextRun('Link')->setUrl($entry->getLink())
                    ->setTooltip('Link');;
4

2 回答 2

0

该问题已在开发分支中修复。

链接:https ://github.com/PHPOffice/PHPPowerPoint/commit/43bea92220396a3c7178f649afbc961be28828c1

于 2014-12-16T14:15:15.063 回答
0

我现在通过在正确的位置添加一个形状来做到这一点。

/* SET HYPERLINK WITH SHAPE */
$shape = $slide->createRichTextShape();
$shape->setWidth($this->cell_link_width)
      ->setHeight($this->cell_height)
      ->setOffsetX($this->cell_link_offsetX)
       >setOffsetY($this->tableOffsetY + $height);
        $textLink = $shape->createTextRun('Link');
        $textLink->getHyperlink()->setUrl('http://' . $entry->getLink())
       >setTooltip('http://' . $entry->getLink());

我已经编写了一个算法并定义了一个变量 line_height 以将链接设置在正确的位置。

这是我的完整功能:

public function createTableSlide($objPHPPowerPoint, $pathLogo, $user, $entries) {

    $slide = $this->createTemplatedSlide($objPHPPowerPoint, $pathLogo, $user);
    /* CREATE TABLE WITH COLUMNS */
    $tableShape = $this->getTable($slide, 6);
    $this->setTableSlideHeader($slide, 'Social Media', 'Twitter', $tableShape);

    /* ADD TABLE ROW */
    $i = 1;
    $height = 22;
    $height_tmp = 0;
    $max_height = 554;
    foreach ($entries as $entry) {
        $height += $height_tmp; 
        $modulId = $entry->getModul()->getId();

        /* NEW SLIDE IF TABLE HEIGHT AT END OF SLIDE */
        if($height >= $max_height){
            $slide = $this->createTemplatedSlide($objPHPPowerPoint, $pathLogo, $user);
            /* CREATE TABLE WITH COLUMNS */
            $tableShape = $this->getTable($slide, 6);
            $this->setTableSlideHeader($slide, 'Social Media', 'Twitter', $tableShape);

            $i = 1;
            $height = 22;
            $height_tmp = 0;
        }

        $row_in_cell = ceil(strlen($entry->getContent()) / $this->char_in_row);

        if ($row_in_cell > 2) {
            $height_tmp = $row_in_cell * $this->line_height + $this->line_height;
        } else {
            $height_tmp = $this->line_height * 3 + 0.8;
        }



        $row = $tableShape->createRow();
        $row->setHeight($this->cell_height);
        $row->getFill()->setFillType(Fill::FILL_SOLID)
                ->setStartColor(new Color('FFFFFFFF'))
                ->setEndColor(new Color('FFFFFFFF'));
        $row->nextCell()->createTextRun(date_format($entry->getDate(), "d.m.Y"));
        $row->nextCell()->createTextRun($entry->getTonality()->getName());
        $row->nextCell()->createTextRun($entry->getAccountname());
        $row->nextCell()->createTextRun($entry->getContent());
        $row->nextCell()->createTextRun($entry->getFollower());
        $row->nextCell()->createTextRun($modulId);
        /* SET HYPERLINK WITH SHAPE */
        $shape = $slide->createRichTextShape();
        $shape->setWidth($this->cell_link_width)
                ->setHeight($this->cell_height)
                ->setOffsetX($this->cell_link_offsetX)
                ->setOffsetY($this->tableOffsetY + $height);
        $textLink = $shape->createTextRun('Link');
        $textLink->getHyperlink()->setUrl('http://' . $entry->getLink())
                ->setTooltip('http://' . $entry->getLink());
        $i++;
    }
}

如果您搜索相同的解决方案,希望它可以帮助您。如果有人有更好的解决方案,他可以回答我:)

于 2014-11-11T11:23:38.740 回答