Describe the bug
Since 3.2.5 , the HTML border="0" attribute on <table> is ignored. Every table is unconditionally assigned the TableGrid style, when the document does not already define it, so a table that explicitly asked for no borders renders as a full grid.
The code intended to handle this is still present in TableExpression.ComposeStyles, but it is unreachable.
This worked up to 3.2.4.
Expected behavior
When table borders is set to 0 or none I expect no borders visible in the output.
E.g. in the reproduction below I expect (taken from 3.2.4):
<w:tblBorders xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:top w:val="none" /><w:left w:val="none" /><w:bottom w:val="none" /><w:right w:val="none" /><w:insideH w:val="none" /><w:insideV w:val="none" /></w:tblBorders>
Repro
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlToOpenXml.dll" Version="3.5.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.5.1" />
</ItemGroup>
</Project>
using System;
using System.IO;
using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using HtmlToOpenXml;
class Program
{
const string Html = @"<table border=""0""><tr><td>A1</td><td>A2</td></tr><tr><td>B1</td><td>B2</td></tr></table>";
static void Main()
{
Console.WriteLine("HtmlToOpenXml " + typeof(HtmlConverter).Assembly.GetName().Version);
using var stream = new MemoryStream();
using var doc = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document);
var mainPart = doc.AddMainDocumentPart();
mainPart.Document = new Document(new Body());
new HtmlConverter(mainPart).ParseBody(Html).GetAwaiter().GetResult();
mainPart.Document.Save();
var tblPr = mainPart.Document.Body.Descendants<Table>().First().GetFirstChild<TableProperties>();
Console.WriteLine("tblStyle : " + (tblPr.TableStyle?.Val?.Value ?? "<none>"));
Console.WriteLine("tblBorders : " + (tblPr.TableBorders?.OuterXml ?? "<NOT EMITTED>"));
var grid = mainPart.StyleDefinitionsPart?.Styles?.Elements<Style>()
.FirstOrDefault(s => s.StyleId?.Value == "TableGrid");
Console.WriteLine("TableGrid : " + (grid?.StyleTableProperties?.TableBorders?.OuterXml ?? "<absent>"));
}
}
Describe the bug
Since
3.2.5, the HTMLborder="0"attribute on<table>is ignored. Every table is unconditionally assigned theTableGridstyle, when the document does not already define it, so a table that explicitly asked for no borders renders as a full grid.The code intended to handle this is still present in
TableExpression.ComposeStyles, but it is unreachable.This worked up to
3.2.4.Expected behavior
When table borders is set to
0ornoneI expect no borders visible in the output.E.g. in the reproduction below I expect (taken from 3.2.4):
<w:tblBorders xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:top w:val="none" /><w:left w:val="none" /><w:bottom w:val="none" /><w:right w:val="none" /><w:insideH w:val="none" /><w:insideV w:val="none" /></w:tblBorders>Repro