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

Free Support Forum - aspose.com

How to get the font properties of a text in a cell?

Hi team,

How to get the font properties(font size, font color & font type) of a text in a table cell.I want to apply the font properties to a newly created node after the table.

Code:
Paragraph p = new Paragraph(doc);
Run run = new Run(doc, “Any String” );
run.getFont().setSize(10);
run.getFont().setStrikeThrough(false);
run.getFont().setColor(Color.BLACK);
p.getRuns().add(run);
p.appendChild(new BookmarkEnd(doc, “MyBookmark”));

In this, the font properties of “Any String” should be same as the “Font property of a text in any table cell of document”. How to achieve this dynamically rather to apply the font size and color every time?

Regards,
Gomathi. N.

@Gomathi

In your case, we suggest you please clone the paragraph node of table’s cell and add it into the document as shown below. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);

Paragraph p = (Paragraph) table.getFirstRow().getFirstCell().getFirstParagraph().deepClone(true);

Run run = (Run)p.getRuns().get(0).deepClone(true);
run.setText("Any String");

p.removeAllChildren();
p.appendChild(run);

doc.getFirstSection().getBody().appendChild(p);

doc.save(MyDir + "19.3.docx");