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

Free Support Forum - aspose.cloud

How to implement getValue method of IMailMergeDataSource in java for Custom dataSource

I want to implement custom DataSource in Java

DataSource dataSource=dao.getTemplateData();
DataSourceMailMerge dataSourceMailMerge=new DataSourceMailMerge(dataSource); doc.getMailMerge().execute(dataSourceMailMerge);

How to implement DataSourceMailMerge class:-

Example below…

Class DataSourceMailMerge implements IMailMergeDataSource {
DataSource dataSource;
public DataSourceMailMerge(DataSource dataSource) {
this.dataSource=dataSource;
}

@Override
public String getTableName() throws Exception {
    return "DatSource";
}

@Override
public boolean moveNext() throws Exception {
    return false;
}

@Override
public boolean getValue(String fieldName, Ref<Object> fieldValue) throws Exception {

    String value= String.valueOf(fieldValue.get());
    switch (fieldName)
    {
        case "FullName":
            value= dataSource.cName;
            return true;
        case "Address":
            value = dataSource.addressLine1;
            return true;
        default:
            fieldValue = null;
            return false;
    }
}

@Override
public IMailMergeDataSource getChildDataSource(String s) throws Exception {
    return null;
}

This topic has been moved to the related forum: https://forum.aspose.com/t/how-to-implement-getvalue-method-of-imailmergedatasource-in-java-for-custom-datasource/263068