@@ -702,4 +702,46 @@ public function testParseTableAndCellWidth()
702
702
$ this ->assertEquals ('dxa ' , $ doc ->getElement ($ xpath )->getAttribute ('w:type ' ));
703
703
}
704
704
705
+ public function testParseCellspacingRowBgColor ()
706
+ {
707
+ $ phpWord = new \PhpOffice \PhpWord \PhpWord ();
708
+ $ section = $ phpWord ->addSection ([
709
+ 'orientation ' => \PhpOffice \PhpWord \Style \Section::ORIENTATION_LANDSCAPE ,
710
+ ]);
711
+
712
+ // borders & backgrounds are here just for better visual comparison
713
+ $ html = <<<HTML
714
+ <table cellspacing="3" bgColor="lightgreen" width="50%" align="center">
715
+ <tr>
716
+ <td>A</td>
717
+ <td>B</td>
718
+ </tr>
719
+ <tr bgcolor="#FF0000">
720
+ <td>C</td>
721
+ <td>D</td>
722
+ </tr>
723
+ </table>
724
+ HTML ;
725
+
726
+ Html::addHtml ($ section , $ html );
727
+ $ doc = TestHelperDOCX::getDocument ($ phpWord , 'Word2007 ' );
728
+
729
+ // uncomment to see results
730
+ file_put_contents ('./table_src.html ' , $ html );
731
+ file_put_contents ('./table_result_ ' .time ().'.docx ' , file_get_contents ( TestHelperDOCX::getFile () ) );
732
+
733
+ $ xpath = '/w:document/w:body/w:tbl/w:tblPr/w:tblCellSpacing ' ;
734
+ $ this ->assertTrue ($ doc ->elementExists ($ xpath ));
735
+ $ this ->assertEquals (3 * 15 , $ doc ->getElement ($ xpath )->getAttribute ('w:w ' ));
736
+ $ this ->assertEquals ('dxa ' , $ doc ->getElement ($ xpath )->getAttribute ('w:type ' ));
737
+
738
+ $ xpath = '/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tcPr/w:shd ' ;
739
+ $ this ->assertTrue ($ doc ->elementExists ($ xpath ));
740
+ $ this ->assertEquals ('lightgreen ' , $ doc ->getElement ($ xpath )->getAttribute ('w:fill ' ));
741
+
742
+ $ xpath = '/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:tcPr/w:shd ' ;
743
+ $ this ->assertTrue ($ doc ->elementExists ($ xpath ));
744
+ $ this ->assertEquals ('FF0000 ' , $ doc ->getElement ($ xpath )->getAttribute ('w:fill ' ));
745
+ }
746
+
705
747
}
0 commit comments