phppresentation 表溢出问题

问题描述

Table going outside the slide

随着单元格高度的增加,表格高度增加并使表格移出幻灯片,因此我希望表格被分割,而外面的部分进入下一张幻灯片 假设第 3 行在幻灯片之外,因此在下一张幻灯片中发送第 3 行

<?PHP

include_once 'Sample_Header.PHP';

use PHPOffice\phppresentation\phppresentation;
use PHPOffice\phppresentation\Style\Border;
use PHPOffice\phppresentation\Style\Color;
use PHPOffice\phppresentation\Style\Fill;

// Create new phppresentation object
echo date('H:i:s') . ' Create new phppresentation object'.EOL;
$objphppresentation = new phppresentation();

// Set properties
echo date('H:i:s') . ' Set properties'.EOL;
$objphppresentation->getDocumentProperties()->setCreator('PHPOffice')
                                  ->setLastModifiedBy('phppresentation Team')
                                  ->setTitle('Sample 06 Title')
                                  ->setSubject('Sample 06 Subject')
                                  ->setDescription('Sample 06 Description')
                                  ->setKeywords('office 2007 openxml libreoffice odt PHP')
                                  ->setCategory('Sample Category');

// Remove first slide
echo date('H:i:s') . ' Remove first slide'.EOL;
$objphppresentation->removeSlideByIndex(0);

// Create slide
echo date('H:i:s') . ' Create slide'.EOL;
$currentSlide = createTemplatedSlide($objphppresentation);

// Create a shape (table)
echo date('H:i:s') . ' Create a shape (table)'.EOL;
$shape = $currentSlide->createTableShape(3);
$shape->setHeight(100);
$shape->setWidth(600);
$shape->setoffsetX(150);
$shape->setoffsetY(150);

// Add row
echo date('H:i:s') . ' Add row'.EOL;
$row = $shape->createRow();
$row->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)
               ->setRotation(90)
               ->setStartColor(new Color('FFE06B20'))
               ->setEndColor(new Color('FFFFFFFF'));
$cell = $row->nextCell();
$cell->setColSpan(3);
$cell->createTextRun('askjbsakbcashbcashkbckashbkashhkasc')->getFont()->setBold(true)->setSize(16);
$cell->getBorders()->getBottom()->setlinewidth(4)
                                ->setLinestyle(Border::LINE_SINGLE)
                                ->setDashStyle(Border::DASH_DASH);
$cell->getActiveParagraph()->getAlignment()
    ->setMarginLeft(10);

// Add row
echo date('H:i:s') . ' Add row'.EOL;
$row = $shape->createRow();
$row->setHeight(20);
$row->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)
               ->setRotation(90)
               ->setStartColor(new Color('FFE06B20'))
               ->setEndColor(new Color('FFFFFFFF'));
$oCell = $row->nextCell();
$oCell->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasnjsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn')->getFont()->setBold(true);
$oCell->getActiveParagraph()->getAlignment()->setMarginLeft(20);
$oCell = $row->nextCell();
$oCell->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasnjsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn')->getFont()->setBold(true);
$oCell = $row->nextCell();
$oCell->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasnjsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn')->getFont()->setBold(true);

foreach ($row->getCells() as $cell) {
    $cell->getBorders()->getTop()->setlinewidth(4)
                                 ->setLinestyle(Border::LINE_SINGLE)
                                 ->setDashStyle(Border::DASH_DASH);
    // if($cell->getHeight()>20){
    //     $nextSlide = createTemplatedSlide($objphppresentation);
    // }
}
$nextSlide = createTemplatedSlide($objphppresentation);

// Add row
echo date('H:i:s') . ' Add row'.EOL;
$row = $shape->createRow();
$row->getFill()->setFillType(Fill::FILL_SOLID)
               ->setStartColor(new Color('FFE06B20'))
               ->setEndColor(new Color('FFE06B20'));
$oCell = $row->nextCell();
$oCell->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn');
$oCell->getActiveParagraph()->getAlignment()
    ->setMarginLeft(30)
    ->setTextDirection(\PHPOffice\phppresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
$oCell = $row->nextCell();
$oCell->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasnvjsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn ');
$oCell->getActiveParagraph()->getAlignment()
    ->setMarginBottom(10)
    ->setMarginTop(20)
    ->setMarginRight(30)
    ->setMarginLeft(40);
$oCell = $row->nextCell();
$oCell->createTextRun('vjsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasnjsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn');

// Add row
echo date('H:i:s') . ' Add row'.EOL;
$row = $shape->createRow();
$row->getFill()->setFillType(Fill::FILL_SOLID)
               ->setStartColor(new Color('FFE06B20'))
               ->setEndColor(new Color('FFE06B20'));
$oCell = $row->nextCell();
$oCell->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn');
$oCell->getActiveParagraph()->getAlignment()->setMarginLeft(40);
$oCell = $row->nextCell();
$oCell->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn');
$oCell = $row->nextCell();
$oCell->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn');

// Add row
echo date('H:i:s') . ' Add row'.EOL;
$row = $shape->createRow();
$row->getFill()->setFillType(Fill::FILL_SOLID)
               ->setStartColor(new Color('FFE06B20'))
               ->setEndColor(new Color('FFE06B20'));
$cellC1 = $row->nextCell();
$textrunc1 = $cellC1->createTextRun('Link');
$textrunc1->getHyperlink()->setUrl('https://github.com/PHPOffice/phppresentation/')->setTooltip('phppresentation');
$cellC1->getActiveParagraph()->getAlignment()->setMarginLeft(50);
$cellC2 = $row->nextCell();
$textrunc2 = $cellC2->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn');
$textrunc2->getFont()->setBold(true);
$textrunc2->getFont()->setSize(12);
$textrunc2->getFont()->setColor(new Color('FF000000'));
$cellC2->createBreak();
$textrunc2 = $cellC2->createTextRun('jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn');
$textrunc2->getFont()->setBold(true);
$textrunc2->getFont()->setSize(14);
$textrunc2->getFont()->setColor(new Color('FF0088FF'));
$cellC3 = $row->nextCell();
$textrunc3 = $cellC3->createTextRun('Link jsdhfljadnfkljancfancjklscnajklnacsjlnsajlcnasjlcnasjlcnlasncjlasnclasncjlasncljasncjlasncljasn');
$textrunc3->getHyperlink()->setUrl('https://github.com')->setTooltip('GitHub');
$cellC3->createBreak();
$textrunc3 = $cellC3->createTextRun('Link Google');
$textrunc3->getHyperlink()->setUrl('https://google.com')->setTooltip('Google');


// Save file
echo write($objphppresentation,basename(__FILE__,'.PHP'),$writers);
if (!CLI) {
    include_once 'Sample_Footer.PHP';
}

解决方法

[<?php

include_once 'Sample_Header.php';

use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Fill;


// Create new PHPPresentation object
echo date('H:i:s') . ' Create new PHPPresentation object'.EOL;
$objPHPPresentation = new PhpPresentation();

// Set properties
echo date('H:i:s') . ' Set properties'.EOL;
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
                                  ->setLastModifiedBy('PHPPresentation Team')
                                  ->setTitle('Sample 06 Title')
                                  ->setSubject('Sample 06 Subject')
                                  ->setDescription('Sample 06 Description')
                                  ->setKeywords('office 2007 openxml libreoffice odt php')
                                  ->setCategory('Sample Category');

// Remove first slide
echo date('H:i:s') . ' Remove first slide'.EOL;
$objPHPPresentation->removeSlideByIndex(0);

// Create slide
echo date('H:i:s') . ' Create slide'.EOL;
$currentSlide = createTemplatedSlide($objPHPPresentation);

// Create a shape (table)
echo date('H:i:s') . ' Create a shape (table)'.EOL;
$shape = $currentSlide->createTableShape(3);
$shape->setHeight(100);
$shape->setWidth(600);
$shape->setOffsetX(150);
$shape->setOffsetY(150);

//info comming ftom database
$info = "abcdef";
$total = 0;
$rows = 0;

for($var=0;$var<50;$var++)
{
    // Add row
    $row+=1;
    addData();
    echo date('H:i:s') . ' Add row'.EOL.$total;
}

function addData(){
    global $total,$info,$objPHPPresentation,$shape;
    compare($objPHPPresentation);
    $row = $shape->createRow();
    $row->getFill()->setFillType(Fill::FILL_SOLID)
               ->setStartColor(new Color('FFE06B20'))
               ->setEndColor(new Color('FFE06B20'));
    $oCell = $row->nextCell();
    $oCell->createTextRun($info);
    $total += strlen($info);
    $oCell->getActiveParagraph()->getAlignment()
                                ->setMarginLeft(30)
                                ->setTextDirection(\PhpOffice\PhpPresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
    $oCell = $row->nextCell();
    $oCell->createTextRun($info);
    $total += strlen($info);
    $oCell->getActiveParagraph()->getAlignment()
                                ->setMarginBottom(10)
                                ->setMarginTop(20)
                                ->setMarginRight(30)
                                ->setMarginLeft(40);
    $oCell = $row->nextCell();
    $oCell->createTextRun($info);
    $total += strlen($info);
}

function compare(){
    global $total,$shape,$row;
    if(!($total<180 && $row<12)){
        echo date('H:i:s') . ' Create slide'.EOL;
        $currentSlide = createTemplatedSlide($objPHPPresentation);
        echo date('H:i:s') . ' Create a shape (table)'.EOL;
        $shape = $currentSlide->createTableShape(3);
        $shape->setHeight(100);
        $shape->setWidth(600);
        $shape->setOffsetX(150);
        $shape->setOffsetY(150);
        $total = 0;
        $row = 0;
    }
}


// Save file
echo write($objPHPPresentation,basename(__FILE__,'.php'),$writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
}][1]