Sample_04_Table.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. include_once 'Sample_Header.php';
  3. use PhpOffice\PhpPresentation\PhpPresentation;
  4. use PhpOffice\PhpPresentation\Style\Border;
  5. use PhpOffice\PhpPresentation\Style\Color;
  6. use PhpOffice\PhpPresentation\Style\Fill;
  7. // Create new PHPPresentation object
  8. echo date('H:i:s') . ' Create new PHPPresentation object'.EOL;
  9. $objPHPPresentation = new PhpPresentation();
  10. // Set properties
  11. echo date('H:i:s') . ' Set properties'.EOL;
  12. $objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
  13. ->setLastModifiedBy('PHPPresentation Team')
  14. ->setTitle('Sample 06 Title')
  15. ->setSubject('Sample 06 Subject')
  16. ->setDescription('Sample 06 Description')
  17. ->setKeywords('office 2007 openxml libreoffice odt php')
  18. ->setCategory('Sample Category');
  19. // Remove first slide
  20. echo date('H:i:s') . ' Remove first slide'.EOL;
  21. $objPHPPresentation->removeSlideByIndex(0);
  22. // Create slide
  23. echo date('H:i:s') . ' Create slide'.EOL;
  24. $currentSlide = createTemplatedSlide($objPHPPresentation);
  25. // Create a shape (table)
  26. echo date('H:i:s') . ' Create a shape (table)'.EOL;
  27. $shape = $currentSlide->createTableShape(3);
  28. $shape->setHeight(200);
  29. $shape->setWidth(600);
  30. $shape->setOffsetX(150);
  31. $shape->setOffsetY(300);
  32. // Add row
  33. echo date('H:i:s') . ' Add row'.EOL;
  34. $row = $shape->createRow();
  35. $row->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)
  36. ->setRotation(90)
  37. ->setStartColor(new Color('FFE06B20'))
  38. ->setEndColor(new Color('FFFFFFFF'));
  39. $cell = $row->nextCell();
  40. $cell->setColSpan(3);
  41. $cell->createTextRun('Title row')->getFont()->setBold(true)->setSize(16);
  42. $cell->getBorders()->getBottom()->setLineWidth(4)
  43. ->setLineStyle(Border::LINE_SINGLE)
  44. ->setDashStyle(Border::DASH_DASH);
  45. $cell->getActiveParagraph()->getAlignment()
  46. ->setMarginLeft(10);
  47. // Add row
  48. echo date('H:i:s') . ' Add row'.EOL;
  49. $row = $shape->createRow();
  50. $row->setHeight(20);
  51. $row->getFill()->setFillType(Fill::FILL_GRADIENT_LINEAR)
  52. ->setRotation(90)
  53. ->setStartColor(new Color('FFE06B20'))
  54. ->setEndColor(new Color('FFFFFFFF'));
  55. $oCell = $row->nextCell();
  56. $oCell->createTextRun('R1C1')->getFont()->setBold(true);
  57. $oCell->getActiveParagraph()->getAlignment()->setMarginLeft(20);
  58. $oCell = $row->nextCell();
  59. $oCell->createTextRun('R1C2')->getFont()->setBold(true);
  60. $oCell = $row->nextCell();
  61. $oCell->createTextRun('R1C3')->getFont()->setBold(true);
  62. foreach ($row->getCells() as $cell) {
  63. $cell->getBorders()->getTop()->setLineWidth(4)
  64. ->setLineStyle(Border::LINE_SINGLE)
  65. ->setDashStyle(Border::DASH_DASH);
  66. }
  67. // Add row
  68. echo date('H:i:s') . ' Add row'.EOL;
  69. $row = $shape->createRow();
  70. $row->getFill()->setFillType(Fill::FILL_SOLID)
  71. ->setStartColor(new Color('FFE06B20'))
  72. ->setEndColor(new Color('FFE06B20'));
  73. $oCell = $row->nextCell();
  74. $oCell->createTextRun('R2C1');
  75. $oCell->getActiveParagraph()->getAlignment()
  76. ->setMarginLeft(30)
  77. ->setTextDirection(\PhpOffice\PhpPresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
  78. $oCell = $row->nextCell();
  79. $oCell->createTextRun('R2C2');
  80. $oCell->getActiveParagraph()->getAlignment()
  81. ->setMarginBottom(10)
  82. ->setMarginTop(20)
  83. ->setMarginRight(30)
  84. ->setMarginLeft(40);
  85. $oCell = $row->nextCell();
  86. $oCell->createTextRun('R2C3');
  87. // Add row
  88. echo date('H:i:s') . ' Add row'.EOL;
  89. $row = $shape->createRow();
  90. $row->getFill()->setFillType(Fill::FILL_SOLID)
  91. ->setStartColor(new Color('FFE06B20'))
  92. ->setEndColor(new Color('FFE06B20'));
  93. $oCell = $row->nextCell();
  94. $oCell->createTextRun('R3C1');
  95. $oCell->getActiveParagraph()->getAlignment()->setMarginLeft(40);
  96. $oCell = $row->nextCell();
  97. $oCell->createTextRun('R3C2');
  98. $oCell = $row->nextCell();
  99. $oCell->createTextRun('R3C3');
  100. // Add row
  101. echo date('H:i:s') . ' Add row'.EOL;
  102. $row = $shape->createRow();
  103. $row->getFill()->setFillType(Fill::FILL_SOLID)
  104. ->setStartColor(new Color('FFE06B20'))
  105. ->setEndColor(new Color('FFE06B20'));
  106. $cellC1 = $row->nextCell();
  107. $textRunC1 = $cellC1->createTextRun('Link');
  108. $textRunC1->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation');
  109. $cellC1->getActiveParagraph()->getAlignment()->setMarginLeft(50);
  110. $cellC2 = $row->nextCell();
  111. $textRunC2 = $cellC2->createTextRun('RichText with');
  112. $textRunC2->getFont()->setBold(true);
  113. $textRunC2->getFont()->setSize(12);
  114. $textRunC2->getFont()->setColor(new Color('FF000000'));
  115. $cellC2->createBreak();
  116. $textRunC2 = $cellC2->createTextRun('Multiline');
  117. $textRunC2->getFont()->setBold(true);
  118. $textRunC2->getFont()->setSize(14);
  119. $textRunC2->getFont()->setColor(new Color('FF0088FF'));
  120. $cellC3 = $row->nextCell();
  121. $textRunC3 = $cellC3->createTextRun('Link Github');
  122. $textRunC3->getHyperlink()->setUrl('https://github.com')->setTooltip('GitHub');
  123. $cellC3->createBreak();
  124. $textRunC3 = $cellC3->createTextRun('Link Google');
  125. $textRunC3->getHyperlink()->setUrl('https://google.com')->setTooltip('Google');
  126. // Save file
  127. echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
  128. if (!CLI) {
  129. include_once 'Sample_Footer.php';
  130. }