@@ -40,21 +40,22 @@ public function write()
40
40
$ rowCount = count ($ rows );
41
41
if ($ rowCount > 0 ) {
42
42
$ content .= '<table> ' . PHP_EOL ;
43
- for ($ i = 0 ; $ i < count ( $ rows ) ; $ i ++) {
43
+ for ($ i = 0 ; $ i < $ rowCount ; $ i ++) {
44
44
/** @var $row \PhpOffice\PhpWord\Element\Row Type hint */
45
45
$ rowStyle = $ rows [$ i ]->getStyle ();
46
46
// $height = $row->getHeight();
47
47
$ tblHeader = $ rowStyle ->isTblHeader ();
48
48
$ content .= '<tr> ' . PHP_EOL ;
49
49
$ rowCells = $ rows [$ i ]->getCells ();
50
- for ($ j = 0 ; $ j < count ($ rowCells ); $ j ++) {
50
+ $ rowCellCount = count ($ rowCells );
51
+ for ($ j = 0 ; $ j < $ rowCellCount ; $ j ++) {
51
52
$ cellStyle = $ rowCells [$ j ]->getStyle ();
52
53
$ cellColSpan = $ cellStyle ->getGridSpan ();
53
54
$ cellRowSpan = 1 ;
54
55
$ cellVMerge = $ cellStyle ->getVMerge ();
55
56
// If this is the first cell of the vertical merge, find out how man rows it spans
56
57
if ($ cellVMerge === 'restart ' ) {
57
- for ($ k = $ i + 1 ; $ k < count ( $ rows ) ; $ k ++) {
58
+ for ($ k = $ i + 1 ; $ k < $ rowCount ; $ k ++) {
58
59
$ kRowCells = $ rows [$ k ]->getCells ();
59
60
if (isset ($ kRowCells [$ j ])) {
60
61
if ($ kRowCells [$ j ]->getStyle ()->getVMerge () === 'continue ' ) {
@@ -70,14 +71,14 @@ public function write()
70
71
// Ignore cells that are merged vertically with previous rows
71
72
if ($ cellVMerge !== 'continue ' ) {
72
73
$ cellTag = $ tblHeader ? 'th ' : 'td ' ;
73
- $ cellColSpanAttr = (is_numeric ($ cellColSpan ) && ($ cellColSpan > 1 ) ? " colspan= \"{$ cellColSpan }\"" : "" );
74
- $ cellRowSpanAttr = ($ cellRowSpan > 1 ? " rowspan= \"{$ cellRowSpan }\"" : "" );
74
+ $ cellColSpanAttr = (is_numeric ($ cellColSpan ) && ($ cellColSpan > 1 ) ? " colspan= \"{$ cellColSpan }\"" : '' );
75
+ $ cellRowSpanAttr = ($ cellRowSpan > 1 ? " rowspan= \"{$ cellRowSpan }\"" : '' );
75
76
$ content .= "< {$ cellTag }{$ cellColSpanAttr }{$ cellRowSpanAttr }> " . PHP_EOL ;
76
77
$ writer = new Container ($ this ->parentWriter , $ rowCells [$ j ]);
77
78
$ content .= $ writer ->write ();
78
79
if ($ cellRowSpan > 1 ) {
79
80
// There shouldn't be any content in the subsequent merged cells, but lets check anyway
80
- for ($ k = $ i + 1 ; $ k < count ( $ rows ) ; $ k ++) {
81
+ for ($ k = $ i + 1 ; $ k < $ rowCount ; $ k ++) {
81
82
$ kRowCells = $ rows [$ k ]->getCells ();
82
83
if (isset ($ kRowCells [$ j ])) {
83
84
if ($ kRowCells [$ j ]->getStyle ()->getVMerge () === 'continue ' ) {
0 commit comments