Document is not generating

16-10 PPT Pre-Approved Flex Mod - Non BK.docx (60.8 KB)

this is docx which I want to generate using aspose.words mail merge feature I have json file
naidu.docx (2.4 KB)

above is json from which I want to generate can you please update me where is the issue

@Vaibhavi_Lad

Unfortunately, I can’t access or download files directly from the links you provided. However, I can guide you through the process of using the Aspose.Words for .NET Mail Merge feature effectively. Here are the steps to achieve your goal:

Steps to Generate a DOCX File using Aspose.Words Mail Merge

  1. Setup Your Environment:
    Ensure you have Aspose.Words for .NET installed. You can download it from the official Aspose website.

  2. Prepare Your Template:
    Make sure your Word document (16-10 PPT Pre-Approved Flex Mod - Non BK.docx) contains the merge fields where you want the JSON data to be inserted.

  3. Prepare Your JSON Data:
    Ensure your JSON data (naidu.json) is structured correctly. Here’s an example of what the JSON data might look like:

    {
        "EmployeeName": "John Doe",
        "Department": "Sales",
        "Address": "1234 Elm Street",
        "City": "Springfield"
    }
    
  4. Perform the Mail Merge:
    Use Aspose.Words to load the template document and perform the mail merge with the JSON data.

Sample Code

Here is a sample code snippet to demonstrate how you can use Aspose.Words for .NET to perform a mail merge with JSON data.

using Aspose.Words;
using Aspose.Words.MailMerging;
using Aspose.Words.MailMerging.Templates;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;

public void MailMergeUsingJson()
{
    // Load the template document
    Document doc = new Document("16-10 PPT Pre-Approved Flex Mod - Non BK.docx");

    // Load the JSON data
    string jsonData = File.ReadAllText("naidu.json");
    JObject jsonObject = JsonConvert.DeserializeObject<JObject>(jsonData);

    // Convert JSON data to DataTable
    DataTable dataTable = JsonToDataTable(jsonObject);

    // Perform the mail merge
    doc.MailMerge.Execute(dataTable.Rows[0]);

    // Save the document
    doc.Save("Output.docx");
}

private DataTable JsonToDataTable(JObject json)
{
    DataTable dataTable = new DataTable();
    foreach (var property in json.Properties())
    {
        dataTable.Columns.Add(property.Name);
    }

    DataRow row = dataTable.NewRow();
    foreach (var property in json.Properties())
    {
        row[property.Name] = property.Value;
    }
    dataTable.Rows.Add(row);

    return dataTable;
}

Explanation

  1. Load the Template Document: The Document class is used to load the Word document.
  2. Load the JSON Data: The JSON data is read from a file and deserialized into a JObject.
  3. Convert JSON Data to DataTable: The JSON data is converted into a DataTable format that Aspose.Words can use for mail merging.
  4. Perform the Mail Merge: The MailMerge.Execute method is used to perform the mail merge.
  5. Save the Document: The merged document is saved.

Troubleshooting Tips

  • Check Merge Fields: Ensure that the merge fields in your Word document match the keys in your JSON data.
  • Debug JSON Data: Print or inspect the JSON data to ensure it is correctly formatted.
  • Check for Errors: Look for any exceptions or errors in the console or output window.

Additional Resources

{
“ProductCode”: “3A542B5DAB”,
“LoanNumber”: “0041923095”,
“Borrower1_FirstName”: “JUAN”,
“Borrower1_LastName”: “CARLOS AVINA”,
“Borrower2_FirstName”: “VICTOR MANUEL”,
“Borrower2_LastName”: “RODRIGUEZ”,
“Borrower3_FirstName”: “MOISES”,
“Borrower3_LastName”: “ROGELIO HERNANDEZ”,
“Borrower4_FirstName”: “”,
“Borrower4_LastName”: “”,
“Borrower5_FirstName”: “”,
“Borrower5_LastName”: “”,
“Borrower6_FirstName”: “”,
“Borrower6_LastName”: “”,
“Borrower7_FirstName”: “”,
“Borrower7_LastName”: “”,
“Borrower8_FirstName”: “”,
“Borrower8_LastName”: “”,
“Borrower9_FirstName”: “”,
“Borrower9_LastName”: “”,
“Borrower10_FirstName”: “”,
“Borrower10_LastName”: “”,
“PropertyStateCode”: “CA”,
“Companyname”: “Mr. Cooper”,
“LossMitAddress”: “8950 Cypress Waters Blvd., Coppell, TX 75019”,
“LossMitPhone”: “888-400-9856”,
“ScheduledTrialPmt_Due1”: “05/01/2025”,
“ScheduledTrialPmt_Due2”: “06/01/2025”,
“ScheduledTrialPmt_Due3”: “07/01/2025”,
“ScheduledTrialPmt_Due4”: “”,
“ScheduledTrialPmt_Amt1”: 1765.89,
“ScheduledTrialPmt_Amt2”: 1765.89,
“ScheduledTrialPmt_Amt3”: 1765.89,
“ScheduledTrialPmt_Amt4”: null,
“DisasterIND”: “PANDEMIC”,
“Website”: “www.mrcooper.com”,
“AgentPhoneFee”: “15.01”,
“CSPhone”: “877-456-7890”,
“CompanyNameBody”: “LoanServ Inc”,
“RegPayment”: “PO Box 1234, TX”,
“OvernightAddrPO”: “Overnight Dept”,
“OvernightAddr”: “456 Express Ln, TX 75001”,
“MoneyGramCode”: “12345”,
“BrandID”: “VUL”,
“QuickCollectCodeCity”: “OSWALD”,
“QuickCollectCodeState”: “TX”,
“First Payment Effective Date”: “09/01/2025”,
“Current Monthly Payment”: 1200.00,
“Principal and Interest Payment Amount”: “800.00”,
“Pre Mod Escrow Payment”: “400.00”,
“Current Interest Rate”: “5.25”,
“Loan Remaining Term”: “240”,
“Pre Mod Maturity Date”: “01/01/2045”,
“CurrentDeferredAmt”: “8000.00”,
“Mod Lien Current Unpaid Principal Balance”: “150000.00”,
“First Perm Payment Due Date”: “11/01/2025”,
“Modified Monthly Payment amount”: 950.00,
“New PI Payment Amount”: “700.00”,
“Post Mod Escrow Payment”: “250.00”,
“Modified Interest Rate”: “3.25”,
“Modified Term”: “480”,
“Modified Maturity Date”: “01/01/2065”,
“ProposedDeferredAmt”: “12000.00”,
“New Unpaid Principal Balance Amount”: “165000.00”,
“HHFIND”: “1”,
“Investor”: “FHLMC”,
“AVMVendor”: “Outamation”,
“BPOFlag”: “2”
}

@Vaibhavi_Lad Please note that Aspose.Words does not provide API to process JSON data. For such cases, you need to implement IMailMergeDataSource interface and work with JSON according to your requirement.

You can also convert your JSON to DataSet/DataTable and then use it for mail merge.

Also, you can check Mail Merge with XML Data Source in Java|Aspose.Words for Java