File tree 2 files changed +8
-3
lines changed
src/Html2OpenXml/Expressions/Table
2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -31,9 +31,6 @@ public override IEnumerable<OpenXmlElement> Interpret (ParsingContext context)
31
31
{
32
32
var childElements = base . Interpret ( context ) ;
33
33
34
- if ( ! childElements . Any ( ) ) // Word requires that the cell is not empty
35
- childElements = [ new Paragraph ( ) ] ;
36
-
37
34
var cell = new TableCell ( cellProperties ) ;
38
35
39
36
if ( cellNode . ColumnSpan > 1 )
@@ -46,6 +43,13 @@ public override IEnumerable<OpenXmlElement> Interpret (ParsingContext context)
46
43
cellProperties . VerticalMerge = new ( ) { Val = MergedCellValues . Restart } ;
47
44
}
48
45
46
+ // Word requires at least one paragraph in a cell
47
+ // OpenXmlValidator does not catch this error
48
+ if ( ! childElements . OfType < Paragraph > ( ) . Any ( ) )
49
+ {
50
+ childElements = childElements . Append ( new Paragraph ( ) ) ;
51
+ }
52
+
49
53
cell . Append ( childElements ) ;
50
54
return [ cell ] ;
51
55
}
Original file line number Diff line number Diff line change @@ -493,6 +493,7 @@ public void NestedTable_ReturnsTableInsideTable()
493
493
var cell = elements [ 0 ] . GetFirstChild < TableRow > ( ) ? . GetFirstChild < TableCell > ( ) ;
494
494
Assert . That ( cell , Is . Not . Null ) ;
495
495
Assert . That ( cell . HasChild < Table > ( ) , Is . True ) ;
496
+ Assert . That ( cell . HasChild < Paragraph > ( ) , Is . True , "Word requires at least a paragraph" ) ;
496
497
}
497
498
498
499
[ Test ]
You can’t perform that action at this time.
0 commit comments