...
//--- A 2-D jagged array of values
//--- This is a "transposed" array with columns in the first
//--- dimension and rows in the second
object[][] data = new object[][]{
new string[]{"Knoxville", "Boston",
"Washington", "Seattle",
"Chicago", "New York",
"Atlanta", "Los Angeles",
"Houston"},
new string[]{"Tennessee", "Massachusetts",
"DC", "Washington",
"Illinois", "New York",
"Georgia", "California",
"Texas"}
};
//--- Names array, elements correspond to merge field names
string[] names = new string[] { "City", "State" };
WordTemplate wt = new WordTemplate();
wt.Open(Server.MapPath("template/MergeFieldTest.doc"));
//--- Set the mail merge
//--- The data source is the 2-D jagged data array
//--- MaxRows is set to ALL_ROWS, which allows all rows to be imported
//--- Transpose is set to true to handle the transposed array
wt.SetMailMerge(data, names, WordTemplate.ALL_ROWS, true);
wt.Process();
wt.Save(Page.Response, "output.doc", false);
|