MailMergeProcessor
MailMergeProcessor class
Performs a mail merge: fills the placeholders of a template presentation with data and creates either a single presentation with the template slides repeated for every data set, or a separate presentation for every data set.
public sealed class MailMergeProcessor : IMailMergeProcessor
Constructors
| Name | Description |
|---|---|
| MailMergeProcessor() | Initializes a new instance of the MailMergeProcessor class. |
Methods
| Name | Description |
|---|---|
| MergeToMultiplePresentations(IPresentation, IMailMergeDataSource, MailMergedPresentationHandler) | Creates a separate presentation for every data set of the data source, fills it with the data and passes it to the handler. See MailMergedPresentationHandler for the rules the handler must follow. |
| MergeToMultiplePresentations(IPresentation, Stream, MailMergedPresentationHandler) | Reads the data from a stream, creates a separate presentation for every data set, fills it with the data and passes it to the handler. The supported data formats are described in IMailMergeProcessor. See MailMergedPresentationHandler for the rules the handler must follow. |
| MergeToMultiplePresentations(IPresentation, string, MailMergedPresentationHandler) | Reads the data from a file, creates a separate presentation for every data set, fills it with the data and passes it to the handler. The supported data formats are described in IMailMergeProcessor. See MailMergedPresentationHandler for the rules the handler must follow. |
| MergeToSinglePresentation(IPresentation, IMailMergeDataSource) | Creates a single presentation in which the slides of the template are repeated for every data set of the data source and filled with its data. |
| MergeToSinglePresentation(IPresentation, Stream) | Reads the data from a stream and creates a single presentation in which the slides of the template are repeated for every data set and filled with its data. The supported data formats are described in IMailMergeProcessor. |
| MergeToSinglePresentation(IPresentation, string) | Reads the data from a file and creates a single presentation in which the slides of the template are repeated for every data set and filled with its data. The supported data formats are described in IMailMergeProcessor. |
Remarks
Placeholders. A placeholder is a field name in double curly braces, for example {{title}}, placed in the text of the template. Placeholders are replaced on the slides, including grouped shapes and table cells, and in the speaker notes. Placeholders on layout and master slides are not replaced. Field names are case-insensitive. A placeholder whose field is not present in the data set is left unchanged. The inserted value takes the formatting of the first character of the placeholder. Values must not contain placeholder text: such a value may be replaced again with the value of another field.
Template. The template is not modified. It must contain at least one slide.
Data. The data is either built in code with IMailMergeDataSource or read from a CSV, XLSX, JSON or XML file or stream. The format is detected by the content, not by the file extension. Data that is not recognized as any of these formats causes NotSupportedException. Data that is recognized but does not follow the format described below causes InvalidDataException; its message contains the location of the error in the data. Every format must contain at least one data set.
JSON. The root object contains the sets array. Every set contains the fields array; every field contains the name and the value string. The optional version must be "1.0". The optional field type must be "text". Property names are case-sensitive; unknown properties are ignored. The data is read as UTF-8, or as UTF-16 when the data starts with a byte order mark.
{
"version": "1.0",
"sets": [
{
"fields": [
{ "name": "title", "value": "Laptop X1" },
{ "name": "price", "value": "$999" }
]
},
{
"fields": [
{ "name": "title", "value": "Tablet S2" },
{ "name": "price", "value": "$499" }
]
}
]
}
XML. The root element template contains the sets element. Every set element contains field elements; every field contains the name and the value elements. An empty value element is an empty string. Element names are case-sensitive; unknown elements and comments are ignored. The encoding is taken from the XML declaration. Document type definitions (DTD) are not allowed.
<?xml version="1.0" encoding="utf-8"?>
<template>
<sets>
<set>
<field><name>title</name><value>Laptop X1</value></field>
<field><name>price</name><value>$999</value></field>
</set>
<set>
<field><name>title</name><value>Tablet S2</value></field>
<field><name>price</name><value>$499</value></field>
</set>
</sets>
</template>
CSV. Values are separated by a semicolon. The first row contains the field names and ends at the first empty name. Every following row is a data set; the data ends at the first empty row. Missing values at the end of a row are empty strings; values beyond the field names are ignored. A value that contains a semicolon, a quotation mark or a line break must be enclosed in quotation marks, and a quotation mark inside it is doubled. The data is read as UTF-8, or as UTF-16 when the data starts with a byte order mark.
title;price;description
Laptop X1;$999;"14"" display; 16 GB RAM"
Tablet S2;$499;
XLSX. The data is read from the first worksheet with the same rules as CSV: the first row contains the field names and ends at the first empty cell, every following row is a data set, and the data ends at the first empty row. An empty cell is an empty string. Numbers are converted to text with the invariant culture.
See Also
- interface IMailMergeProcessor
- namespace Aspose.Slides.MailMerge
- assembly Aspose.Slides