[英]Mail merge in C# with n copies
我只想創建一個C#程序,它將讀取一個單詞模板並使用郵件合並功能創建n個副本。要替換的數據是名稱和地址,模板中的其余內容應該保持不變。 誰能告訴我該怎么做?
您可以使用Aspose.Word處理Word Object模型,而不必在應該運行程序的位置安裝Office(以使用interop),我正在使用Aspose.Word生成Word文檔。
鏈接到Aspose: http : //www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx
它的工作相當不錯:)
我不確定您是要運行郵件合並還是要復制模板。 我不能用c#幫助您,但是VBA的這一片段可能會給您一些想法。
strDir = CurrentProject.Path
strMailmergeDataFilename = strDir & Format(Now, "yymmdd_hhnnss") & ".txt"
' Create CSV from database for use with mailmerge '
' This is a separate function that simply exports the sql '
' ExportSQLToCSV SQL, strMailmergeDataFilename '
'Open merge template '
Set objWordDoc = GetObject(strDir & MergeDocumentFilename, "Word.Document")
objWordDoc.Application.Visible = True
'Format:=0 ''0 = wdOpenFormatAuto'
'Add the data source '
objWordDoc.MailMerge.OpenDataSource _
Name:=strMailmergeDataFilename, ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=0, _
Connection:="", SQLStatement:="", SQLStatement1:=""
'Type some text at a bookmark, you could use .range property '
Selection.Goto What:=wdGoToBookmark, Name:="signaturetext"
Selection.TypeText Text:="You are here"
'Run mailmerge '
objWordDoc.MailMerge.Destination = 0 '0 = wdSendToNewDocument'
objWordDoc.MailMerge.Execute
objWordDoc.Application.ActiveDocument.PrintPreview
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.