|
17 | 17 |
|
18 | 18 | namespace PhpOffice\PhpWord\Writer\Word2007\Element;
|
19 | 19 |
|
20 |
| -use PhpOffice\PhpWord\Style\Cell; |
| 20 | +use PhpOffice\PhpWord\Element\Cell as CellElement; |
| 21 | +use PhpOffice\PhpWord\Element\Row as RowElement; |
| 22 | +use PhpOffice\PhpWord\Style\Cell as CellStyle; |
21 | 23 | use PhpOffice\PhpWord\Style\Table as TableStyle;
|
22 | 24 | use PhpOffice\PhpWord\Writer\Word2007\Style\Cell as CellStyleWriter;
|
23 | 25 | use PhpOffice\PhpWord\Writer\Word2007\Style\Table as TableStyleWriter;
|
@@ -89,51 +91,66 @@ public function write()
|
89 | 91 |
|
90 | 92 | // Table rows
|
91 | 93 | for ($i = 0; $i < $rowCount; $i++) {
|
92 |
| - $row = $rows[$i]; |
93 |
| - $height = $row->getHeight(); |
94 |
| - $rowStyle = $row->getStyle(); |
| 94 | + $this->writeRow($rows[$i]); |
| 95 | + } |
| 96 | + $this->xmlWriter->endElement(); |
| 97 | + } |
| 98 | + } |
95 | 99 |
|
96 |
| - $this->xmlWriter->startElement('w:tr'); |
97 |
| - if (!is_null($height) || $rowStyle->isTblHeader() || $rowStyle->isCantSplit()) { |
98 |
| - $this->xmlWriter->startElement('w:trPr'); |
99 |
| - if (!is_null($height)) { |
100 |
| - $this->xmlWriter->startElement('w:trHeight'); |
101 |
| - $this->xmlWriter->writeAttribute('w:val', $height); |
102 |
| - $this->xmlWriter->writeAttribute('w:hRule', ($rowStyle->isExactHeight() ? 'exact' : 'atLeast')); |
103 |
| - $this->xmlWriter->endElement(); |
104 |
| - } |
105 |
| - if ($rowStyle->isTblHeader()) { |
106 |
| - $this->xmlWriter->startElement('w:tblHeader'); |
107 |
| - $this->xmlWriter->writeAttribute('w:val', '1'); |
108 |
| - $this->xmlWriter->endElement(); |
109 |
| - } |
110 |
| - if ($rowStyle->isCantSplit()) { |
111 |
| - $this->xmlWriter->startElement('w:cantSplit'); |
112 |
| - $this->xmlWriter->writeAttribute('w:val', '1'); |
113 |
| - $this->xmlWriter->endElement(); |
114 |
| - } |
115 |
| - $this->xmlWriter->endElement(); |
116 |
| - } |
117 |
| - foreach ($row->getCells() as $cell) { |
118 |
| - $cellStyle = $cell->getStyle(); |
119 |
| - $width = $cell->getWidth(); |
120 |
| - $this->xmlWriter->startElement('w:tc'); |
121 |
| - $this->xmlWriter->startElement('w:tcPr'); |
122 |
| - $this->xmlWriter->startElement('w:tcW'); |
123 |
| - $this->xmlWriter->writeAttribute('w:w', $width); |
124 |
| - $this->xmlWriter->writeAttribute('w:type', 'dxa'); |
125 |
| - $this->xmlWriter->endElement(); // w:tcW |
126 |
| - if ($cellStyle instanceof Cell) { |
127 |
| - $styleWriter = new CellStyleWriter($this->xmlWriter, $cellStyle); |
128 |
| - $styleWriter->write(); |
129 |
| - } |
130 |
| - $this->xmlWriter->endElement(); // w:tcPr |
131 |
| - $this->parentWriter->writeContainerElements($this->xmlWriter, $cell); |
132 |
| - $this->xmlWriter->endElement(); // w:tc |
133 |
| - } |
134 |
| - $this->xmlWriter->endElement(); // w:tr |
| 100 | + /** |
| 101 | + * Write row |
| 102 | + */ |
| 103 | + private function writeRow(RowElement $row) |
| 104 | + { |
| 105 | + $height = $row->getHeight(); |
| 106 | + $rowStyle = $row->getStyle(); |
| 107 | + |
| 108 | + $this->xmlWriter->startElement('w:tr'); |
| 109 | + if (!is_null($height) || $rowStyle->isTblHeader() || $rowStyle->isCantSplit()) { |
| 110 | + $this->xmlWriter->startElement('w:trPr'); |
| 111 | + if (!is_null($height)) { |
| 112 | + $this->xmlWriter->startElement('w:trHeight'); |
| 113 | + $this->xmlWriter->writeAttribute('w:val', $height); |
| 114 | + $this->xmlWriter->writeAttribute('w:hRule', ($rowStyle->isExactHeight() ? 'exact' : 'atLeast')); |
| 115 | + $this->xmlWriter->endElement(); |
| 116 | + } |
| 117 | + if ($rowStyle->isTblHeader()) { |
| 118 | + $this->xmlWriter->startElement('w:tblHeader'); |
| 119 | + $this->xmlWriter->writeAttribute('w:val', '1'); |
| 120 | + $this->xmlWriter->endElement(); |
| 121 | + } |
| 122 | + if ($rowStyle->isCantSplit()) { |
| 123 | + $this->xmlWriter->startElement('w:cantSplit'); |
| 124 | + $this->xmlWriter->writeAttribute('w:val', '1'); |
| 125 | + $this->xmlWriter->endElement(); |
135 | 126 | }
|
136 | 127 | $this->xmlWriter->endElement();
|
137 | 128 | }
|
| 129 | + foreach ($row->getCells() as $cell) { |
| 130 | + $this->writeCell($cell); |
| 131 | + } |
| 132 | + $this->xmlWriter->endElement(); // w:tr |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Write cell |
| 137 | + */ |
| 138 | + private function writeCell(CellElement $cell) |
| 139 | + { |
| 140 | + $cellStyle = $cell->getStyle(); |
| 141 | + |
| 142 | + $this->xmlWriter->startElement('w:tc'); |
| 143 | + $this->xmlWriter->startElement('w:tcPr'); |
| 144 | + $this->xmlWriter->startElement('w:tcW'); |
| 145 | + $this->xmlWriter->writeAttribute('w:w', $cell->getWidth()); |
| 146 | + $this->xmlWriter->writeAttribute('w:type', 'dxa'); |
| 147 | + $this->xmlWriter->endElement(); // w:tcW |
| 148 | + if ($cellStyle instanceof CellStyle) { |
| 149 | + $styleWriter = new CellStyleWriter($this->xmlWriter, $cellStyle); |
| 150 | + $styleWriter->write(); |
| 151 | + } |
| 152 | + $this->xmlWriter->endElement(); // w:tcPr |
| 153 | + $this->parentWriter->writeContainerElements($this->xmlWriter, $cell); |
| 154 | + $this->xmlWriter->endElement(); // w:tc |
138 | 155 | }
|
139 | 156 | }
|
0 commit comments