Word Table - adding new rows and preserve the same font as in the document

I am adding new rows to an empty table. The document has a Calibri font but when I add a new row, its using the default font. What is the best way to keep the same font?

Here is the sample code:

 Bookmark bookmark = getBookmarkContainsName(doc, "sampletable");
 Table table = (bookmark != null) ? ((Table)bookmark.getBookmarkStart().getAncestor(NodeType.TABLE)) : null;
 if (table != null) {
 	int amdSize = listofHM.size();
 	for (int i = 0; i < amdSize; i++) {
 		HashMap < String,
 		String > amdHM = listofHM.get(i);
 		Row row = new Row(doc);
 		Cell cell1 = new Cell(doc);
 		cell1.appendChild(new Paragraph(doc));
 		cell1.getFirstParagraph().appendChild(new Run(doc, amdHM.get("date_submitted")));
 		Cell cell2 = new Cell(doc);
 		cell2.appendChild(new Paragraph(doc));
 		cell2.getFirstParagraph().appendChild(new Run(doc, amdHM.get("date_received")));
 		Cell cell3 = new Cell(doc);
 		cell3.appendChild(new Paragraph(doc));
 		cell3.getFirstParagraph().appendChild(new Run(doc, amdHM.get("briefdescription")));

@mp2 You can clone the row from the table and update it’s content to keep formatting. Could you please attach your sample document here for testing? We will check the issue and provide you more information.

Also, as I can see you can easily achieve what you need using Mail Merge With Regions or using LINQ Reporting Engine.

Here is the sample word:
SampleTable.docx (12.3 KB)

Also, I have a scenario where if the table has 10records, I need to insert rows in one table (in the first page) but if its more than 10 records, then I need to insert rows in the Appendix Page which is the last page. But the source is same. How can we achieve this?

I did try the mailmerge regions options and its pretty cool. I have the same mailmerge table start and end in both of these tables ( one in first page and one in appendix page) but when I ran the mailmerge, it only populated on first page. I am wondering how can we update mailmerge tables

@mp2 Yes, Mail Merge With Regions should fit your requirements. You can use MailMerge. MergeDuplicateRegions option to fill regions with the same name.

Regarding your conditions, you can try using regions with different names and fill one region or another depending on the number of records and them remove unused region using the corresponding cleanup options.
Also, you can put your regions into IF field condition and show or hide the region depending on the condition.

Thank you very much @alexey.noskov

1 Like