How to: Validate the ObjectDataSource Contained in the Spreadsheet MailMerge Template
- 2 minutes to read
Loading the mail merge templates with the ObjectDataSource data source may cause undesired behavior if the data source is contained in a compiled assembly. This example illustrates how to use a custom service that implements the IObjectDataSourceValidationService interface to validate an ObjectDataSource contained in the loaded mail merge template and prevent the data source from loading.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-validate-objectdatasource-in-the-spreadsheet-mail-merge-template-t515368
static void Main() {
Workbook workbook = new DevExpress.Spreadsheet.Workbook();
workbook.ReplaceService<IObjectDataSourceValidationService>(new MyObjectDataSourceValidationService());
workbook.LoadDocument("EmployeesMailMergeTemplate.xlsx");
var result = workbook.GenerateMailMergeDocuments();
result[0].SaveDocument("result.xlsx");
System.Diagnostics.Process.Start("result.xlsx");
}