Odso Class

Specifies the Office Data Source Object (ODSO) settings for a mail merge data source.
Inheritance Hierarchy
SystemObject
  Aspose.Words.SettingsOdso

Namespace:  Aspose.Words.Settings
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public class Odso

The Odso type exposes the following members.

Constructors
  NameDescription
Public methodOdso
Initializes a new instance of the Odso class
Properties
  NameDescription
Public propertyCode exampleColumnDelimiter
Specifies the character which shall be interpreted as the column delimiter used to separate columns within external data sources. The default value is 0 which means there is no column delimiter defined.
Public propertyCode exampleDataSource
Specifies the location of the external data source to be connected to a document to perform the mail merge. The default value is an empty string.
Public propertyCode exampleDataSourceType
Specifies the type of the external data source to be connected to as part of the ODSO connection information for this mail merge. The default value is Default.
Public propertyCode exampleFieldMapDatas
Gets or sets a collection of objects that specify how columns from the external data source are mapped to the predefined merge field names in the document. This object is never null.
Public propertyCode exampleFirstRowContainsColumnNames
Specifies that a hosting application shall treat the first row of data in the specified external data source as a header row containing the names of each column in the data source. The default value is false.
Public propertyCode exampleRecipientDatas
Gets or sets a collection of objects that specify inclusion/exclusion of individual records in the mail merge. This object is never null.
Public propertyCode exampleTableName
Specifies the particular set of data that a source shall be connected to within an external data source. The default value is an empty string.
Public propertyCode exampleUdlConnectString
Specifies the Universal Data Link (UDL) connection string used to connect to an external data source. The default value is an empty string.
Methods
  NameDescription
Public methodCode exampleClone
Returns a deep clone of this object.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)
Remarks

ODSO seems to be the "new" way the newer Microsoft Word versions prefer to use when specifying certain types of data sources for a mail merge document. ODSO probably first appeared in Microsoft Word 2000.

The use of ODSO is poorly documented and the best way to learn how to use the properies of this object is to create a document with a desired data source manually in Microsoft Word and then open that document using Aspose.Words and examine the properties of the MailMergeSettings and Odso objects. This is a good approach to take if you want to learn how to programmatically configure a data source, for example.

You do not normally need to create objects of this class directly because ODSO settings are always available via the Odso property.

Examples
Shows how to execute an Office Data Source Object mail merge with MailMergeSettings.
// We'll create a simple document that will act as a destination for mail merge data
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Dear ");
builder.InsertField("MERGEFIELD FirstName", "<FirstName>");
builder.Write(" ");
builder.InsertField("MERGEFIELD LastName", "<LastName>");
builder.Writeln(": ");
builder.InsertField("MERGEFIELD Message", "<Message>");

// Also we'll need a data source, in this case it will be an ASCII text file
// We can use any character we want as a delimiter, in this case we'll choose '|'
// The delimiter character is selected in the ODSO settings of mail merge settings
string[] lines = { "FirstName|LastName|Message",
    "John|Doe|Hello! This message was created with Aspose Words mail merge." };
string dataSrcFilename = ArtifactsDir + "Document.MailMergeSettings.DataSource.txt";

File.WriteAllLines(dataSrcFilename, lines);

// Set the data source, query and other things
MailMergeSettings settings = doc.MailMergeSettings;
settings.MainDocumentType = MailMergeMainDocumentType.MailingLabels;
settings.CheckErrors = MailMergeCheckErrors.Simulate;
settings.DataType = MailMergeDataType.Native;
settings.DataSource = dataSrcFilename;
settings.Query = "SELECT * FROM " + doc.MailMergeSettings.DataSource;
settings.LinkToQuery = true;
settings.ViewMergedData = true;

Assert.AreEqual(MailMergeDestination.Default, settings.Destination);
Assert.False(settings.DoNotSupressBlankLines);

// Office Data Source Object settings
Odso odso = settings.Odso;
odso.DataSource = dataSrcFilename;
odso.DataSourceType = OdsoDataSourceType.Text;
odso.ColumnDelimiter = '|';
odso.FirstRowContainsColumnNames = true;

// ODSO/MailMergeSettings objects can also be cloned
Assert.AreNotSame(odso, odso.Clone());
Assert.AreNotSame(settings, settings.Clone());

// The mail merge will be performed when this document is opened 
doc.Save(ArtifactsDir + "Document.MailMergeSettings.docx");
See Also