Quantcast
Channel: Open XML Format SDK forum
Viewing all articles
Browse latest Browse all 1288

Bad fill style in table headers with OpenXML

$
0
0

I am generating documents with OpenXML and adding tables, and I have found a strange issue. I am generating the headers with the following code:

 DocumentFormat.OpenXml.Wordprocessing.TableRow tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow();

            // Create a cell.
            DocumentFormat.OpenXml.Wordprocessing.TableCell tc1 = new DocumentFormat.OpenXml.Wordprocessing.TableCell();

            // Specify the width property of the table cell.
            tc1.Append(new DocumentFormat.OpenXml.Wordprocessing.TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }));

            tc1.TableCellProperties.Shading = new Shading() {
                Color = "auto",
                Fill = HexConverter(System.Drawing.Color.LightGray),
                Val = ShadingPatternValues.Clear
            };

            DocumentFormat.OpenXml.Wordprocessing.Paragraph p1 = tc1.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Paragraph());
            DocumentFormat.OpenXml.Wordprocessing.Run r1 = p1.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Run());
            DocumentFormat.OpenXml.Wordprocessing.Text t1 = r1.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text("Factor"));            

            r1.RunProperties = new DocumentFormat.OpenXml.Wordprocessing.RunProperties();
            r1.RunProperties.RunFonts = new RunFonts();
            r1.RunProperties.RunFonts.Ascii = "Arial";
            r1.RunProperties.FontSize = new FontSize() { Val = "24" };
            r1.RunProperties.Bold = new Bold() { Val = OnOffValue.FromBoolean(true) };

            // Append the table cell to the table row.
            tr.Append(tc1);

But when the table is visualized in word, although the header cell is filled with gray color, the intial margin inside the cell appears in white. if I open the docx file with other controls that can show docx it appears in the right way, but not in Word. Any ideas about what is happening?

thanks a lot


Viewing all articles
Browse latest Browse all 1288

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>