We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cloned rows font size affects whole document

Hi there,


in a current project we use aspose.words (.Net) to fill out a table in a word file.
We clone the second row of the table, identified through a bookmark, and append it to the table, then we set the text in the cells, including text size.

When we change the font size, the font size is changed in other parts of the document aswell. As visible in the attached files. Somehow the font size of the different parts is connected.

There are no other modifications through code except cloneing the rows and inserting text in the cells through:

c = row.Cells[index];
c.RemoveAllChildren();

Paragraph p = new Paragraph(doc);
p.ParagraphFormat.Style.Font.Size = 24;
p.ParagraphFormat.Style.Font.Name = “Arial”;

Run r = new Run(doc, “–/--”);
p.AppendChild®;

c.AppendChild§;

with “row” being the current row.

This also happens when i add a Paragraph with Font.Size and Name to the end of the document.

When we load another document and access the table cell and first paragraph format, the font is also wrong wheras the ParagraphBreakFont property seems to be correct.

Aspose.words version is 15.12.0.0.

Slightly urgent, so any anwer would be appreciated.

Kind regards,
Torsten

Hi Torsten,


Thanks for your inquiry. The problem occurs because the following line changes the formatting of “Normal” style which is used in many places of your document.

p.ParagraphFormat.Style.Font.Size = 24;

Please try using the following code instead:

Document doc = new Document(MyDir + @“template.docx”);

Bookmark bm = doc.Range.Bookmarks["Item"];

Row row = (Row) bm.BookmarkStart.GetAncestor(NodeType.Row);

// Clone this Row 5 times

for (int i = 0; i < 5; i++)

{

Row newRow = (Row)row.Clone(true);

foreach (Cell cell in newRow)

{

cell.LastParagraph.RemoveAllChildren();

cell.LastParagraph.Runs.Add(new Run(doc, "new text" + i));

cell.LastParagraph.Runs[0].Font.Size = 24;

cell.LastParagraph.Runs[0].Font.Name = "Arial";

}

row.ParentTable.AppendChild(newRow);

}

doc.Save(MyDir + @"16.1.0.docx");


Hope, this helps.

Best regards,

Thanks for your response.


I mixed up paragraph and run format.

Thx again