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.

Wed Mar 02, 2016 3:13 pm

I have a problem as below:
1) Open a word file, it's OK.
2) in the word file, there is an table with 3 rows inside, it's OK.
3) Insert a row before the last row, like this:

Dim insertrow As Spire.Doc.TableRow = table.Rows(i - 1).Clone()
table.Rows.Insert(i, insertrow);

the row inserted will have the same font size. it's OK.

4) Add a new row below the last row, like this:
row = table.AddRow();
But the new row will not has the same font size like the row above!

If I can get the textRange from the paragraph, then I can use the textRange.CharacterFormat.FontSize.
but I can only get the textRange from ApendText, not an existing paragraph.
It's so strange!

I know I can create a style like this:
ParagraphStyle style = new ParagraphStyle(document);
style.Name = "FontStyle";
style.CharacterFormat.FontName = "Century Gothic";
style.CharacterFormat.FontSize = 20;
document.Styles.Add(style);
p.ApplyStyle(style.Name);

But I just need to copy the same all styles from the last row. So I don't think it's a good idea to create a new style like this.

thank you .
yours,
ivan

ivanchain
 
Posts: 30
Joined: Wed Jan 22, 2014 12:42 am

Thu Mar 03, 2016 3:15 am

Hi ivan,

Thanks for posting.
You can try the following solution to add a new row below the last row.
Code: Select all
    Table table = document.Sections[0].Tables[0] as Table;
            TableRow lastrow = table.LastRow;
            //Add a new row below the last row and let new row keeps the same style with last row
            table.Rows.Add(lastrow.Clone());
            TableRow newRow = table.LastRow;
            //Rewrite new text for new row.
            newRow.Cells[0].Paragraphs[0].Text = "Test41";



This code is to get textRange from existing paragraph.
Code: Select all
TextRange range= (lastrow..Cells[0].ChildObjects[0] as Paragraph).ChildObjects[0] as TextRange;


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Mar 07, 2016 6:42 am

Hello,

Have you tried the solution provided by Amy? Has the issue been resolved?

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc