Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
Table | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
write | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Writer\ODText\Style; |
19 | |
20 | /** |
21 | * Table style writer. |
22 | * |
23 | * @since 0.11.0 |
24 | */ |
25 | class Table extends AbstractStyle |
26 | { |
27 | /** |
28 | * Write style. |
29 | */ |
30 | public function write(): void |
31 | { |
32 | /** @var \PhpOffice\PhpWord\Style\Table $style Type hint */ |
33 | $style = $this->getStyle(); |
34 | if (!$style instanceof \PhpOffice\PhpWord\Style\Table) { |
35 | return; |
36 | } |
37 | $xmlWriter = $this->getXmlWriter(); |
38 | |
39 | $xmlWriter->startElement('style:style'); |
40 | $xmlWriter->writeAttribute('style:name', $style->getStyleName()); |
41 | $xmlWriter->writeAttribute('style:family', 'table'); |
42 | $xmlWriter->startElement('style:table-properties'); |
43 | //$xmlWriter->writeAttribute('style:width', 'table'); |
44 | $xmlWriter->writeAttribute('style:rel-width', 100); |
45 | $xmlWriter->writeAttribute('table:align', 'center'); |
46 | $xmlWriter->writeAttributeIf($style->isBidiVisual(), 'style:writing-mode', 'rl-tb'); |
47 | $xmlWriter->endElement(); // style:table-properties |
48 | $xmlWriter->endElement(); // style:style |
49 | |
50 | $cellWidths = $style->getColumnWidths(); |
51 | $countCellWidths = $cellWidths === null ? 0 : count($cellWidths); |
52 | |
53 | for ($i = 0; $i < $countCellWidths; ++$i) { |
54 | $width = $cellWidths[$i]; |
55 | $xmlWriter->startElement('style:style'); |
56 | $xmlWriter->writeAttribute('style:name', $style->getStyleName() . '.' . $i); |
57 | $xmlWriter->writeAttribute('style:family', 'table-column'); |
58 | $xmlWriter->startElement('style:table-column-properties'); |
59 | $xmlWriter->writeAttribute('style:column-width', number_format($width * 0.0017638889, 2, '.', '') . 'cm'); |
60 | $xmlWriter->endElement(); // style:table-column-properties |
61 | $xmlWriter->endElement(); // style:style |
62 | } |
63 | } |
64 | } |