Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have created a table in word using OpenXML in which i have to fill a table cell (Header Table Heading) with light grey

Any Help!!

Thanks in advance

What I have tried:

TableRow tr1 = new TableRow();
TableCell tc11 = new TableCell();
TableCellProperties tcp = new TableCellProperties();
GridSpan gridSpan = new GridSpan();
gridSpan.Val = 11;
Paragraph p11 = new Paragraph();
ParagraphProperties pp11 = new ParagraphProperties();
pp11.Justification = new Justification() { Val = JustificationValues.Center };
Run r11 = new Run();
RunProperties rp11 = new RunProperties();
rp11.Bold = new Bold();
r11.Append(rp11);
r11.Append(new Text(""+"My text"));
p11.Append(r11);
tcp.Append(gridSpan);
tc11.Append(tcp);
tc11.Append(p11);
tr1.Append(tc11);
table1.Append(tr1);
Posted
Updated 21-Dec-22 17:07pm
v2

1 solution

I was not sure myself, so I used Google: How do change the foreground color of a table cell in word file using openxml using C - Google Search[^] and found this: How can I modify the foreground and background color of an OpenXML TableCell?[^] ... That was the first result of many. If not that, have a look at the others.
 
Share this answer
 
Comments
Manojkumar-dll 21-Dec-22 23:09pm    
Thanks !!! But the references in the internet doesn't seems to help me to solve this in my case it's quit confusing
Graeme_Grant 21-Dec-22 23:16pm    
Does not help how? Why confusing? You replied super quickly. Did you look at other links at those solutions too in the 4 minutes between when I posted and your reply???
Graeme_Grant 21-Dec-22 23:20pm    
IDK, this is pretty clear to me and I have not worked with it before...

// Create the TableCellProperties object
TableCellProperties tcp = new TableCellProperties(
    new TableCellWidth { Type = TableWidthUnitValues.Auto, }
);
// Create the Shading object
DocumentFormat.OpenXml.Wordprocessing.Shading shading = 
    new DocumentFormat.OpenXml.Wordprocessing.Shading() {
    Color = "auto",
    Fill = "ABCDEF",
    Val = ShadingPatternValues.Clear
};
// Add the Shading object to the TableCellProperties object
tcp.Append(shading);
// Add the TableCellProperties object to the TableCell object
tc.Append(tcp);

That is a total of 4 lines of code.
Manojkumar-dll 21-Dec-22 23:32pm    
Sincere apology and tons of thanks it works Thank you so much sir!!!
Graeme_Grant 22-Dec-22 1:49am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900