Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Sep 06, 2019 1:30 am

HI,

Is it possible to change the styling of a table within a word document and have the font change ?

I've noticed that within WORD itself, changing a table style does not change the actual font or its size. Does Spire.Doc give you this ability?

kaimon
 
Posts: 16
Joined: Fri May 17, 2019 4:04 am

Fri Sep 06, 2019 3:08 am

Hi,

Thanks for your inquiry.
Changing the table style will not change the font or size with Spire.
Below sample code for changing table style:
Code: Select all
Table table = sec.Tables[0] as Table;
table.ApplyStyle(DefaultTableStyle.MediumShading1Accent2);

Below code for changing font of paragraphs in table.
Code: Select all
            ParagraphStyle style = new ParagraphStyle(doc);
            style.Name = "MyStyle";
            //font name
            style.CharacterFormat.FontName = "Arial";
            //font size
            style.CharacterFormat.FontSize = 14;
            doc.Styles.Add(style);
            Table table = sec.Tables[0] as Table;
            for (int i = 0; i < table.Rows.Count; i++)
            {
                for (int j = 0; j < table.Rows[i].Cells.Count; j++)
                {
                    TableCell cell = table.Rows[i].Cells[j];
                    foreach (Paragraph para in cell.Paragraphs)
                    {
                        //apply style
                        para.ApplyStyle(style.Name);
                    }
                }
            }


If you still have the issue, please provide your input file and expected result for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Sep 10, 2019 4:58 am

Thanks. That code works. However, is it possible to apply a standard table style on top of this to change the properties of a table other than the font? This would seem silly to manage via code instead of the built in word styling options.

kaimon
 
Posts: 16
Joined: Fri May 17, 2019 4:04 am

Tue Sep 10, 2019 6:07 am

Hi,

Thanks for your feedback.
Sorry that I am not quite understand about your question, could you please describe it in detail?

Many thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc