首页 新闻 会员 周边 捐助

有关C#操作word中邮件合并的问题

0
悬赏园豆:60 [已关闭问题] 关闭于 2011-12-31 16:25

昨天创建了一个word宏,代码如下

ActiveDocument.MailMerge.OpenDataSource Name:= _
        "C:\Documents and Settings\Smile\桌面\新建 Microsoft Office Excel 工作表.xlsx", _
        ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
        Format:=wdOpenFormatAuto, Connection:= _
        "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Documents and Settings\Smile\桌面\新建 Microsoft Office Excel 工作表.xlsx;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type" _
        , SQLStatement:="SELECT * FROM `Sheet1$`", SQLStatement1:="", SubType:= _
        wdMergeSubTypeAccess
    Selection.MoveRight Unit:=wdCharacter, Count:=3
    ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldMergeField _
        , Text:="""排名"""
    With ActiveDocument.MailMerge
        .Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=False
    End With
    Windows("新建 Microsoft Office Word 文档 (2).docx").Activate
End Sub

请问 如果我用一个IList泛型或者datatable做为数据源的话,ActiveDocument.MailMerge.OpenDataSource 这一段该怎么写,

With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With

这一段又该怎么写,哪位高手来帮帮忙啊~

阿拉米斯的主页 阿拉米斯 | 初学一级 | 园豆:92
提问于:2011-12-29 09:02
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册