Hello,
Thank you for your inquiry.
To maintain the same paragraph style for cells, you can first copy the row and then modify the cell content. You can refer to the following sample code:
- Code: Select all
//Create a document
Document document = new Document();
//Load the file
document.LoadFromFile(@"test.docx");
//Get table
Spire.Doc.Section section = document.Sections[0];
Spire.Doc.Table table = section.Tables[0] as Spire.Doc.Table;
Spire.Doc.TableRow tableRowOne = table.Rows[0];
//Copy row
Spire.Doc.TableRow copyRow = tableRowOne.Clone();
//Insert new row
table.Rows.Insert(1, copyRow);
//Change the data
for (int i = 0; i < copyRow.Cells.Count; i++)
{
Spire.Doc.TableCell tc = copyRow.Cells[i];
//Delete other paragraphs and keep only one
for (int p= tc.Paragraphs.Count-1; p>=0 ; p--)
{
if(p!=0)
{
tc.Paragraphs.RemoveAt(p);
}
else
{
//Directly modify to ensure the same paragraph style
Spire.Doc.Documents.Paragraph paragraph = tc.Paragraphs[p];
paragraph.Text = "Added";
}
}
}
document.SaveToFile(@"out.docx", FileFormat.Docx);
If you have any further questions, please feel free to contact.
Sincerely,
Amin
E-iceblue support team