Hyperlink PHPPowerpoint在表格单元格中设置超链接

Hyperlink PHPPowerpoint在表格单元格中设置超链接,hyperlink,cell,phppowerpoint,Hyperlink,Cell,Phppowerpoint,我想在表格单元格中设置超链接: /* ADD TABLE ROW */ foreach ($entries as $entry) { $row = $tableShape->createRow(); $row->getFill()->setFillType(Fill::FILL_SOLID) ->setStartColor(new Color('FFFFFFFF'))

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

/* 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');;

我现在在正确的位置添加一个形状

/* 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());
我已经写了一个算法,并定义了一个可变的线高度来设置链接的正确位置

以下是我的完整功能:

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++;
    }
}

希望它能帮助你,如果你寻找相同的解决方案。如果有人有更好的解决方案,他可以回答我:

这个问题已经在development分支中解决了

链接: