C# Word - MailMerge Processing in C#.NET
Provides C# Demo Codes for Word MeilMerge Processing to Users
Related .net document control helps:
asp.net excel viewer: ASP.NET Excel Viewer in C# Control (MVC & WebForms): view Office Excel document in web browser.
asp.net image viewer: ASP.NET Image Viewer Control(MVC & WebForms): view, annotate, redact, convert image files in html, JQuery
asp.net pdf viewer: ASP.NET PDF Viewer Control: view, navigate, zoom Adobe PDF document in C# ASP.NET
asp.net mvc pdf editor: ASP.NET MVC PDF Viewer & Editor: view, annotate, redact, edit PDF document in C# ASP.NET MVC
asp.net powerpoint viewer: ASP.NET PowerPoint Document Viewer Control (MVC & WebForms): view ppt, pptx files online in C# using ASP.NET
asp.net multipage tiff viewer: ASP.NET Tiff Viewer: view, annotate multipage Tiff images in ASP.NET MVC, WebForms using C# Control
asp.net pdf editor: EdgePDF: ASP.NET PDF Editor Web Control: Online view, annotate, redact, edit, process, convert PDF documents
Overview
C#.NET Word document MailMerge Interface control (XDoc.Word).
c# create pdf with password,
generate pdf thumbnail c#,
itextsharp add image to pdf vb.net,
add watermark text to pdf using itextsharp c#,
c# tiffbitmapdecoder example,
c# wpf preview pdf.
It can help C# users to execute mail-merge.
C# DLLs: MailMerge Processing
Add references:
RasterEdge.Imaging.Basic.dll
RasterEdge.XDoc.Office.Inner.Common.dll
RasterEdge.Imaging.Drawing.dll
RasterEdge.Imaging.Processing.dll
RasterEdge.XDoc.Office.Inner.Office03.dll
RasterEdge.Imaging.Font.dll
RasterEdge.XDoc.Word.dll
RasterEdge.XImage.Raster.Core.dll
RasterEdge.XImage.Raster.dll
Use corresponding namespaces;
using RasterEdge.Imaging.Basic;
using RasterEdge.XDoc.Word;
Execute MailMerge in OpenXML File with Data Source
In C# class programming, you can use specific APIs to process mail-merge.
c# compress pdf size,
rotate pdf pages using c#,
how to generate pdf in c#,
vb.net code to merge pdf files,
how to add image in pdf using itext in c#,
c# convert bitmap to pdf,
vb.net convert pdf to bitmap.
You may use a preset template and XML file which contains data source, and execute mail-merge by using code sample below.
//Document file path
String docFilePath = @"";
String xmlFilePath = @"";
//Open the document on local disk.
DOCXDocument document = DOCXDocument.Open();
//Create data from xml file
DataSet ds = new DataSet();
ds.ReadXml(xmlFilePath);
DataTable dt = ds.Tables[0];
int index = 0;
foreach (DataRow row in dt.Rows)
{
IDocument doc = document.GetDocument().Clone();
IMailMerge mailMgrge = doc.GetMailMerge();
if (mailMgrge != null)
{
mailMgrge.Execute(row);
}
//Save document after execute
doc.Save(@"" + index.ToString() + ".docx");
index++;
}
|
Execute MailMerge in Microsoft Access Database by Using Data Source(X86 Only)
You may also execute mail-merge by using data source in Microsoft Access database as follow.
show image in asp.net core,
asp.net pdf editor,
asp net mvc 5 pdf viewer,
asp.net c# pdf viewer control,
free pdf preview in asp net c#,
asp.net remove image from pdf page,
c# asp.net open word document.
String connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"" + "Customers.mdb";
String docFilePath = @"";
OleDbConnection conn = new OleDbConnection(connString);
try
{
conn.Open();
// Get data from a database.
OleDbCommand cmd = new OleDbCommand("SELECT * FROM Customers", conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable data = new DataTable();
da.Fill(data);
//Open the document
DOCXDocument document0 = DOCXDocument.Open(docFilePath );
int counter = 1;
// Loop though all records in the data source.
foreach (DataRow row in data.Rows)
{
// Clone the template instead of loading it from disk (for speed).
IDocument doc = document0.GetDocument().Clone();
// Execute mail merge.
IMailMerge mailMerge = doc.GetMailMerge();
if (mailMerge != null)
{
mailMerge.Execute(row);
}
// Save the document.
doc.Save(@"" + counter.ToString() + ".docx");
counter++;
}
}
catch
{
}
|
Execute MailMerge in Field by Using Data Source
You can also execute mail-merge in Word document by data source from string array objects as follow.
String docFilePath = @"";
//Open the document
DOCXDocument document1 = DOCXDocument.Open(docFilePath );
String[] fieldNames = new String[] {"RecipientName", "SenderName", "FaxNumber", "PhoneNumber","Subject", "Body", "Urgent", "ForReview", "PleaseComment", "Date"};
String[] fieldValues = new String[] {"Josh", "Jenny", "123456789", "8888888", "Hello","Test message 1", "one", "two", "three", "2015-01-01"};
IDocument doc2 = document1.GetDocument();
IMailMerge mailMerge0 = doc2.GetMailMerge();
if (mailMerge0 != null)
{
mailMerge0.Execute(fieldNames, fieldValues);
}
doc2.Save(@"");
|