forked from PHPOffice/PHPPresentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample_04_Table.php
144 lines (130 loc) · 4.91 KB
/
Sample_04_Table.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?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(200);
$shape->setWidth(600);
$shape->setOffsetX(150);
$shape->setOffsetY(300);
// 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('Title row')->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('R1C1')->getFont()->setBold(true);
$oCell->getActiveParagraph()->getAlignment()->setMarginLeft(20);
$oCell = $row->nextCell();
$oCell->createTextRun('R1C2')->getFont()->setBold(true);
$oCell = $row->nextCell();
$oCell->createTextRun('R1C3')->getFont()->setBold(true);
foreach ($row->getCells() as $cell) {
$cell->getBorders()->getTop()->setLineWidth(4)
->setLineStyle(Border::LINE_SINGLE)
->setDashStyle(Border::DASH_DASH);
}
// 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('R2C1');
$oCell->getActiveParagraph()->getAlignment()
->setMarginLeft(30)
->setTextDirection(PhpOffice\PhpPresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
$oCell = $row->nextCell();
$oCell->createTextRun('R2C2');
$oCell->getActiveParagraph()->getAlignment()
->setMarginBottom(10)
->setMarginTop(20)
->setMarginRight(30)
->setMarginLeft(40);
$oCell = $row->nextCell();
$oCell->createTextRun('R2C3');
// 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('R3C1');
$oCell->getActiveParagraph()->getAlignment()->setMarginLeft(40);
$oCell = $row->nextCell();
$oCell->createTextRun('R3C2');
$oCell = $row->nextCell();
$oCell->createTextRun('R3C3');
// 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('RichText with');
$textRunC2->getFont()->setBold(true);
$textRunC2->getFont()->setSize(12);
$textRunC2->getFont()->setColor(new Color('FF000000'));
$cellC2->createBreak();
$textRunC2 = $cellC2->createTextRun('Multiline');
$textRunC2->getFont()->setBold(true);
$textRunC2->getFont()->setSize(14);
$textRunC2->getFont()->setColor(new Color('FF0088FF'));
$cellC3 = $row->nextCell();
$textRunC3 = $cellC3->createTextRun('Link Github');
$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';
}