PhpOffice PhpPresentation:创建带表PPT时的行高问题

PhpOffice PhpPresentation:创建带表PPT时的行高问题,php,powerpoint,tablecell,phpoffice,phppresentation,Php,Powerpoint,Tablecell,Phpoffice,Phppresentation,我正在用PHP编写代码来创建PPT文档。在本文中,我以表格格式显示数据,除了一个问题外,其他都很好。对于单元格中的大字符串,当我在创建行时设置40px高度时,行的高度会自动调整大小,因此,一些表行会在幻灯片外打印。 有没有办法计算桌子的高度来比较幻灯片的高度 屏幕扫描: 我的代码是: <?php use PhpOffice\PhpPresentation\IOFactory; use PhpOffice\PhpPresentation\PhpPresentation; use PhpOf

我正在用PHP编写代码来创建PPT文档。在本文中,我以表格格式显示数据,除了一个问题外,其他都很好。对于单元格中的大字符串,当我在创建行时设置40px高度时,行的高度会自动调整大小,因此,一些表行会在幻灯片外打印。 有没有办法计算桌子的高度来比较幻灯片的高度

屏幕扫描:

我的代码是:

<?php 
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape;
use PhpOffice\PhpPresentation\Shape\Drawing;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\Bullet;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Border;
use PhpOffice\PhpPresentation\Style\Fill;

$rowHeight = 0;
$rowCount = count($valuesArray);
$SlideHeight = 514;
$tableHeaderTop = 115;
$HeaderRowHeight = 50;
$AccountName = 'XYZ';
$currentSlide = createTemplatedSlide($objPHPPresentation);
createCommonHeading($objPHPPresentation, $currentSlide, "TEAM", $AccountName);
foreach ($valuesArray as $key => $val) {
    $row = $tableShape->createRow();

    $row->setHeight(40);
    $rowHeight += $row->getHeight();
    $rowCount --;


        $rowNumber++;
        
        if ($key % 2 == 0)
            $row->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(90)->setStartColor(new Color('FFcbcdd4'))->setEndColor(new Color('FFcbcdd4'));
        else
            $row->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(90)->setStartColor(new Color('FFe7e8eb'))->setEndColor(new Color('FFe7e8eb'));
 
        foreach ($val as $k => $v) {
            $textAlignment = Alignment::HORIZONTAL_CENTER;
             $oCell = $row->nextCell();
            $oCell->setWidth(200);
             $oCell->getActiveParagraph()->getAlignment()
                ->setMarginLeft(3)
                ->setMarginRight(3)
                ->setMarginTop(3)
                ->setMarginBottom(3);
                 createCommonTextRun($oCell, 7, $bold, "Montserrat", 0, $v);
            }
            
            
            $currentHeight = $tableHeaderTop + $HeaderRowHeight + $rowHeight;
              if ($currentHeight > $SlideHeight && $rowCount > 0) {
                    $currentSlide = createTemplatedSlide($objPHPPresentation);
                    createCommonHeading($objPHPPresentation, $currentSlide, $headingText, $AccountName);
                    $tableShape = createCommonTable($currentSlide, count($tableHeaderData));
                    createCommonTableHeaderRows($tableShape, $tableHeaderData, $Module);
              
                $rowHeight = 0;
              }
            
            
}


function createCommonTextRun($shape, $size, $setBold, $textStyle, $characterSpacing, $content, $color = null) {

$textRun = $shape->createTextRun($content);
$textRun->getFont()->setBold($setBold)
                   ->setName($textStyle);
$textRun->getFont()->setCharacterSpacing($characterSpacing);
$textRun->getFont()->setSize($size);

if ($color != null)
    $textRun->getFont()->setColor($color);
}

function createTemplatedSlide(PhpOffice\PhpPresentation\PhpPresentation $objPHPPresentation) {
// Create slide
$slide = $objPHPPresentation->createSlide();

// Return slide
return $slide;
}

function createCommonTable($currentSlide, $columnsCount, $continue = FALSE, $Module = "") {
$tableShape = $currentSlide->createTableShape($columnsCount);


return $tableShape;
}
function createCommonTextShape($slide, $height, $width, $offsetX, $offsetY, $horizontalAlignment) {
$shape = $slide->createRichTextShape();
$shape->setHeight($height);
$shape->setWidth($width);
$shape->setOffsetX($offsetX);
$shape->setOffsetY($offsetY);
$shape->getActiveParagraph()->getAlignment()->setHorizontal($horizontalAlignment);

return $shape;
 }

 function createCommonHeading($objPHPPresentation, $currentSlide, $headingText, $AccountName, $Module = "") {
$slideIndex = $objPHPPresentation->getSlideCount();
$headingTextColor = '#000';
$headingAlignment = Alignment::HORIZONTAL_CENTER;
$headingShape = createCommonTextShape($currentSlide, 100, 700, 125, 20, $headingAlignment);
createCommonTextRun($headingShape, 18, false, "Montserrat", 0, $headingText, $headingTextColor);

}
  
function createCommonTableHeaderRows($tableShape, $tableHeaderData, $Module) {
$totalColumns = count($tableHeaderData);
$topWidth = 2;
$row = $tableShape->createRow();

$row->setHeight(50);
$row->getFill()->setFillType(Fill::FILL_SOLID)->setRotation(90)->setStartColor(new Color('FF002f6c'))->setEndColor(new Color('FF002f6c'));
for ($i = 0; $i < $totalColumns; $i++) {
$oCell = $row->nextCell();
    createCommonTextRun($oCell, 9, false, "Montserrat", 0, $tableHeaderData[$i], $cellTextColor);
    $oCell->getActiveParagraph()->getAlignment()->setVertical(Alignment::VERTICAL_CENTER)->setHorizontal( Alignment::HORIZONTAL_CENTER );
}

}