![how to do a mail merge in word 2010 from excel for labels how to do a mail merge in word 2010 from excel for labels](http://www.slipstick.com/images/mail-merge-2013.png)
- #How to do a mail merge in word 2010 from excel for labels how to#
- #How to do a mail merge in word 2010 from excel for labels software#
- #How to do a mail merge in word 2010 from excel for labels code#
Int32 fieldNameLength = fieldText.Length - endMerge Int32 endMerge = fieldText.IndexOf("\\") Word.Range rngFieldCode = myMergeField.Code OWordDoc = (ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing) įoreach (Word.Field myMergeField in oWordDoc.Fields) Word.Document oWordDoc = new Word.Document() Word.Application oWord = new Word.Application()
#How to do a mail merge in word 2010 from excel for labels code#
The code to replace a mergefield with a string is like this: public static void TextToWord(string pWordDoc, string pMergeField, string pValue)
#How to do a mail merge in word 2010 from excel for labels how to#
Here is a simple step by step tutorial on how to do this. In addition, if some of your fields contain line breaks, use this: nr = my_address_text_contains_line_breaks.Replace(Environment.NewLine, "MS_Doc_New_Line") So, your template(c:\my_template.docx) should be like: Ĭongratulations on yourr property.
![how to do a mail merge in word 2010 from excel for labels how to do a mail merge in word 2010 from excel for labels](http://www.addbalance.com/usersguide/images/mailmergeWizard2010.gif)
docx file, and you need to specify your fields in it: Your template(c:\my_template.docx) will be just like normal.
![how to do a mail merge in word 2010 from excel for labels how to do a mail merge in word 2010 from excel for labels](http://www.exceltemplate123.us/wp-content/uploads/2017/11/excel-mail-merge-template-ohsfk-luxury-mail-merge-for-mac-labels-of-excel-mail-merge-templatee5n972.jpg)
Mailmerge(sourceFile, filePath, nr, dt.Columns) String filePath = "c:\final.docx" //this is where your result file locate String sourceFile = "c:\my_template.docx" //this is where you store your template MainDocumentPart mainPart = myDoc.MainDocumentPart Īnd use them like this: DataTable dt = new DataTable() Using (WordprocessingDocument myDoc = true)) If (filepaths != null & filepaths.Length > 1) Item.Text = (string.IsNullOrEmpty(dr.ToString()) ? " " : dr.ToString()) Įlse if (PreItem != null & (PreItem.Text = "")) Var allFooterParas = footer.Descendants() MainDocumentPart mainPart = doc.MainDocumentPart įoreach (FooterPart footerPart in mainPart.FooterParts)
![how to do a mail merge in word 2010 from excel for labels how to do a mail merge in word 2010 from excel for labels](https://docplayer.net/docs-images/42/9929874/images/page_1.jpg)
for the last part(as current item), remove leading content till the first '>' for the first part, remove the last '") & !t.Text.Contains("»")) If (combinedfiled.Contains("«" + cl.ColumnName + "»") || combinedfiled.Contains("")) Item.Text = global:.Replace(item.Text, "") Item.Text = global:.Replace(item.Text, = global:.Replace(item.Text, dr.ToString()) Item.Text = global:.Replace(item.Text, dr.ToString()) If (PreItemConstant = "") || (cl.ColumnName + "»")) || (PreItemConstant.Contains("«") & !PreItemConstant.Contains("»")) Item.Text = global:.Replace(item.Text, or Today Replace("«" + cl.ColumnName + "»", dr.ToString()) Using (WordprocessingDocument doc = WordprocessingDocument.Open(DestinatePath, true)) Public static void Mailmerge(string templatePath, string DestinatePath, DataRow dr, DataColumnCollection columns)Ĭatch //incase the server does not support MS Office Word 2003 / 2007 / 2010įile.Copy(templatePath, DestinatePath, true) While ((size = source.Read(buffer, 0, length)) != 0) If (mstream != null) mstream.WriteTo(target) MemoryStream mstream = source as MemoryStream Public static void CopyStream(Stream source, Stream target) ("",įile.WriteAllBytes(targetFile, documentStream.ToArray()) MainDocumentPart mainPart = template.MainDocumentPart Using (WordprocessingDocument template = WordprocessingDocument.Open(documentStream, true)) Using (Stream tplStream = File.OpenRead(sourceFile))ĭocumentStream = new MemoryStream((int)tplStream.Length) So, add these 4 functions to your project: public static void dotx2docx(string sourceFile, string targetFile) I have perfectly solved this mail merge thing in my project - no third party, no particular demands on IIS, just use OpenXML.
#How to do a mail merge in word 2010 from excel for labels software#
Can't believe third party software charge thousands for interface functions with Word.