无法保存合并的文档 [英] Cannot Save The Merged Document

查看:125
本文介绍了无法保存合并的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

wrdMailMerge = wrdDoc.MailMerge;
            CreateMailMergeDataFile();
              wrdMailMerge.Destination = Microsoft.Office.Interop.Word.WdMailMergeDestination.wdSendToNewDocument;
        wrdMailMerge.Execute(ref oFalse);

        object wdFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF;
        Object fileName = "D:\\test.doc";
        wrdDoc.SaveAs(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
        
        wrdDoc.Saved = true;
        wrdDoc.Close(ref oFalse, ref oMissing, ref oMissing);

       
        
        wrdMailMerge = null;
      
        wrdDoc = null;
        wrdApp = null;
 private void CreateMailMergeDataFile()
    {
         Microsoft.Office.Interop.Word._Document oDataDoc;
        
        
        Object oName = "D:\\DataDoc.doc";
        Object oHeader = "FirstName, LastName, Address, CityStateZip";
        wrdDoc.MailMerge.CreateDataSource(ref oName, ref oMissing,
            ref oMissing, ref oHeader, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing);

        // Open the file to insert data.
        
        oDataDoc = wrdApp.Documents.Open(ref oName, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing);
      
      
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from tblMailMerge", con);
        SqlDataReader dr1;
        dr1 = cmd.ExecuteReader();
        int nR = 2;
        while (dr1.Read())
        {
            FillRow(oDataDoc, nR++, dr1.GetString(1), dr1.GetString(2), dr1.GetString(3), dr1.GetString(4));
            oDataDoc.Tables[1].Rows.Add(ref oMissing);
           // FillRow(oDataDoc, nR++, dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString());
        }
       // con.Close();
        dr1.Close();
        oDataDoc.Tables[1].Rows.Last.Delete();
        //--------------------
       
        
        oDataDoc.Save();
        oDataDoc.Close(ref oFalse, ref oMissing, ref oMissing);

        //throw new Exception("The method or operation is not implemented.");
    }

    private void FillRow(_Document oDoc, int Row, string p_3, string p_4, string p_5, string p_6)
    {
        // Insert the data into the specific cell.
        oDoc.Tables[1].Cell(Row, 1).Range.InsertAfter(p_3);
        oDoc.Tables[1].Cell(Row, 2).Range.InsertAfter(p_4);
        oDoc.Tables[1].Cell(Row, 3).Range.InsertAfter(p_5);
        oDoc.Tables[1].Cell(Row, 4).Range.InsertAfter(p_6);
         implemented.");
    }
       //throw new Exception("The method or operation is not implemented.");
    
}-----------------------



如何保存这些合并的文件..... pls帮助...



HOW TO SAVE THESE MERGED FILE.....pls Help......

推荐答案

您的代码使用无类型且完全未使用的变量显得有些草率. />
Your code look somewhat sloppy using untyped and completely unused variables.
object wdFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF;
Object fileName = "D:\\test.doc";



此外,您可以在CreateMailMergeDataFile中打开和关闭文档,然后打开另一个文档,只需使用一些与邮件合并有关的方法即可.但是,如何知道要合并的文档呢?这不会简单地被记住.您必须同时指定两者.查看msdn中的Word互操作以及如何执行邮件合并.当然有一个例子.

祝你好运!



Furthermore you open and close the document in CreateMailMergeDataFile and then open another document and simply use some methods relating mail merge. But how should it know what documents you want to merge? This won''t simply be remembered. You have to specify both. Look into msdn for Word interop and how to perform a mailmerge. Sure there is an example of it.

Good luck!


这篇关于无法保存合并的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆