Skip to content

Commit

Permalink
Fix framed table size to 100% and avoid to apply border on run level
Browse files Browse the repository at this point in the history
  • Loading branch information
onizet committed Oct 16, 2024
1 parent 52a3957 commit 0ccf42b
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions src/Html2OpenXml/Expressions/BlockElementExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,42 +87,6 @@ public override IEnumerable<OpenXmlElement> Interpret (ParsingContext context)
return [CreateFrame(childElements)];
}

/// <summary>
/// Group all the paragraph inside a framed table.
/// </summary>
private Table CreateFrame(IEnumerable<OpenXmlElement> childElements)
{
TableCell cell;
TableProperties tableProperties;
Table framedTable = new(
tableProperties = new TableProperties {
TableWidth = new() { Type = TableWidthUnitValues.Auto, Width = "0" } // 100%
},
new TableGrid(
new GridColumn() { Width = "5610" }),
new TableRow(
cell = new TableCell(childElements)
)
);

if (!styleBorder.IsEmpty)
{
tableProperties.TableBorders = new TableBorders {
LeftBorder = Converter.ToBorder<LeftBorder>(styleBorder.Left),
RightBorder = Converter.ToBorder<RightBorder>(styleBorder.Right),
TopBorder = Converter.ToBorder<TopBorder>(styleBorder.Top),
BottomBorder = Converter.ToBorder<BottomBorder>(styleBorder.Bottom)
};
}

if (runProperties.Shading != null)
{
cell.TableCellProperties = new() { Shading = (Shading?) runProperties.Shading.Clone() };
}

return framedTable;
}

protected override IEnumerable<OpenXmlElement> Interpret (
ParsingContext context, IEnumerable<AngleSharp.Dom.INode> childNodes)
{
Expand Down Expand Up @@ -216,6 +180,7 @@ protected override void ComposeStyles (ParsingContext context)
if (!styleBorder.IsEmpty)
{
renderAsFramed = true;
runProperties.Border = null;
}

foreach (string className in node.ClassList)
Expand Down Expand Up @@ -394,6 +359,43 @@ private static Paragraph CreateParagraph(ParsingContext context, IList<OpenXmlEl
return p;
}


/// <summary>
/// Group all the paragraph inside a framed table.
/// </summary>
private Table CreateFrame(IEnumerable<OpenXmlElement> childElements)
{
TableCell cell;
TableProperties tableProperties;
Table framedTable = new(
tableProperties = new TableProperties {
TableWidth = new() { Type = TableWidthUnitValues.Pct, Width = "5000" } // 100%
},
new TableGrid(
new GridColumn() { Width = "9442" }),
new TableRow(
cell = new TableCell(childElements)
)
);

if (!styleBorder.IsEmpty)
{
tableProperties.TableBorders = new TableBorders {
LeftBorder = Converter.ToBorder<LeftBorder>(styleBorder.Left),
RightBorder = Converter.ToBorder<RightBorder>(styleBorder.Right),
TopBorder = Converter.ToBorder<TopBorder>(styleBorder.Top),
BottomBorder = Converter.ToBorder<BottomBorder>(styleBorder.Bottom)
};
}

if (runProperties.Shading != null)
{
cell.TableCellProperties = new() { Shading = (Shading?) runProperties.Shading.Clone() };
}

return framedTable;
}

/// <summary>
/// Resolve the next available <see cref="BookmarkStart.Id"/> (they must be unique).
/// </summary>
Expand Down

0 comments on commit 0ccf42b

Please sign in to comment.