View Single Post
 
Old 10-02-2019, 01:25 AM
shahid.majeed shahid.majeed is offline Windows 10 Office 2013
Novice
 
Join Date: Sep 2019
Posts: 4
shahid.majeed is on a distinguished road
Default Apply table style

Hi,
I am new to openxml sdk did not have deep knowledge yet. However what i am trying to do is to create a table with 3 columns and want a special formating for the text inside the table.

I successfully create the table and text in the table cell coming from my database.

However i dont know how to apply style to the table. Write know table follow the default font name, size and colour.

I want table font name should "Arial" size should be 11 and colour should be in RGB 20,50,55.

Can some body help with my code

Code:
                    var res = from bm in wordDoc.MainDocumentPart.Document.Body.Descendants<BookmarkStart>() where bm.Name == "SchedulerTable" select bm;
                    var bookmark = res.First();
                    var parent = bookmark.Parent;
                    DocumentFormat.OpenXml.Wordprocessing.Table table = new DocumentFormat.OpenXml.Wordprocessing.Table();
                    DocumentFormat.OpenXml.Wordprocessing.TableRow tr;
                    DocumentFormat.OpenXml.Wordprocessing.TableCell EventText;
                    DocumentFormat.OpenXml.Wordprocessing.TableCell EventTime;
                    DocumentFormat.OpenXml.Wordprocessing.TableCell EventFreeText;

                    foreach (DataRow row in activeRows)
                    {
                        tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow();
                        EventText = new DocumentFormat.OpenXml.Wordprocessing.TableCell();
                        EventTime = new DocumentFormat.OpenXml.Wordprocessing.TableCell();
                        EventFreeText = new DocumentFormat.OpenXml.Wordprocessing.TableCell();
                        EventText.Append(new Paragraph(new Run(new Text(row.ItemArray[1].ToString()))));
                        EventTime.Append(new Paragraph(new Run(new Text(row.ItemArray[2].ToString()))));
                        EventFreeText.Append(new Paragraph(new Run(new Text(row.ItemArray[3].ToString()))));
                        tr.Append(EventText);
                        tr.Append(EventTime);
                        tr.Append(EventFreeText);
                        table.Append(tr);
                    }
                    parent.InsertAfterSelf(table);
Thanks in advance
Reply With Quote