Inconsistent of bold/normal font when adding data

I have two document, in document BoldFontDocument.do
BoldFontDocument.docx (130.1 KB)

NormalFontDocument.docx (33.2 KB)

cx when i am adding the new row in table with data, in document BoldFontDocument.docx it has having bold font for newly added data
in document NormalFontDocument.docx while adding new row with datait is having normal font.

In both case we are not setting bold flag on newly added row/cell.

Why it is giving different result in different documents with same code.

public static void main(String... args) throws Exception {
    com.aspose.words.License license = new com.aspose.words.License();
    license.setLicense("/home/mohitkumar/myWork/fileList/license/aspose-licence");
    com.aspose.words.Document document = new com.aspose.words.Document("/home/mohitkumar/myWork/fileList/lineItemFontIssue/doc/NormalFontDocument.docx");
    DocumentBuilder documentBuilder = new DocumentBuilder(document);
    NodeCollection childNodes = document.getChildNodes(NodeType.TABLE, true);
    for (Object childNode : childNodes) {
        Table targetTable = (Table) childNode;
        String title = targetTable.getTitle();
        if (StringUtils.isEmpty(title)) {
            continue;
        }

        String[] split = title.split("_");
        String description = targetTable.getDescription();
        if (StringUtil.isEmpty(description)) {
            log.warn("Line item column sequence information not found  in table description , hence existing the method");
            continue;
        }

        if (split.length > 1 && AdminTemplateConstants.LINE_ITEM_TABLE_TITLE.equals(split[0])) {
            Map<String, String> orderToKey = new ObjectMapper().readValue(description, HashMap.class);
            String tableFilterQuery = "";
            Integer templateId = Integer.parseInt(split[1]);

            if (orderToKey.get("filterQuery") != null) {
                tableFilterQuery = orderToKey.get("filterQuery");
                orderToKey.remove("filterQuery");
            }

            if (orderToKey.get("tableName") != null) {
                orderToKey.remove("tableName");
            }

            RowCollection rows = targetTable.getRows();
            for (Row row : rows) {
                if (row != targetTable.getFirstRow()) {
                    rows.remove(row);
                }
            }
            List<Map<String, Object>> datas = new ArrayList<>();

            Map<String, Object> data = new HashMap<>();
            data.put("Ausgewählte Modul/Leistung","test123");
            data.put("Währung","test1234");
            data.put("Servicegebühr","test12345");
            data.put("Subscription (Grundgebühr) bezahlt durch den Kunden","test123456");
            data.put("Transaktionsgebühr bezahlt durch","test12345");
            datas.add(data);
            for (Map<String, Object> dataRow : datas) {
                Row clonedRow = (Row) targetTable.getFirstRow().deepClone(true);
                int sequence = 0;

                for (Cell cell : clonedRow.getCells()) {
                    Font font = null;
                    if (cell.getFirstParagraph().getRuns().getCount() > 0) {
                        font = cell.getFirstParagraph().getRuns().get(0).getFont();
                    }
                    if (cell.getParagraphs().getCount() > 1) {
                        ParagraphCollection paragraphs = cell.getParagraphs();
                        for (Paragraph para : paragraphs) {
                            if (!cell.getFirstParagraph().equals(para)) {
                                para.remove();
                            }
                        }
                    }
                    cell.getFirstParagraph().getChildNodes(NodeType.ANY, false).clear();
                    String columnKey = orderToKey.get(String.valueOf(sequence));
                    sequence++;
                    log.debug("Key : " + columnKey);
                    if (StringUtil.isEmpty(columnKey)) {
                        continue;
                    }
                    Object columnValue = dataRow.get(columnKey);
                    log.debug("Value : " + columnValue);
                    if (columnValue == null) {
                        continue;
                    }
                    Run run = new Run(document, String.valueOf(columnValue));
                    if (font != null) {
                        run.getFont().setName(font.getName());
                        run.getFont().setSize(font.getSize());
                    }
                    cell.getFirstParagraph().getRuns().add(run);
                }
                targetTable.appendChild(clonedRow);


            }
        }
    }
    document.save("/home/mohitkumar/myWork/fileList/lineItemFontIssue/newlygenerated/normalfont.docx");
    //document.save("/home/mohitkumar/myWork/fileList/lineItemFontIssue/newlygenerated/BoldFont.docx");
}

@mohitkumar1991 In the BoldFontDocument.docx document formatting is applied via Heading1 style. You should clear paragraph formatting to get the expected result. Please try to modify your code like this:

cell.getFirstParagraph().getChildNodes(NodeType.ANY, false).clear();
cell.getFirstParagraph().getParagraphFormat().clearFormatting();