有两个Word(WORD1 WORD2)
我想用C#把Word2的内容全部拷到Word1中,请问哪位大虾做过
能发代码看一看吗

解决方案 »

  1.   

    C#读取word1写入word模板,然后将模板写入word2
      

  2.   

    #region 拷贝密封线Word
            /// <summary>
            /// 拷贝密封线Word
            /// </summary>
            /// <param name="strPath"></param>
            private void GetWordContent(object strPath)
            {
                object strSealWordPath = @"F:\SealWord.docx";
                Microsoft.Office.Interop.Word.Application WordAppCopy = null;
                Microsoft.Office.Interop.Word.Document WordDocCopy = null;
                Microsoft.Office.Interop.Word.Application WordAppPaste = null;
                Microsoft.Office.Interop.Word.Document WordDocPaste = null;
                Object Nothing = System.Reflection.Missing.Value;
                string str = string.Empty;
                try
                {
                    WordAppCopy = new Microsoft.Office.Interop.Word.ApplicationClass();
                    WordDocCopy = WordAppCopy.Documents.Open(ref strSealWordPath, ref Nothing, ref Nothing, ref Nothing,
                                                     ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                                                     ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                                                     ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                    WordDocCopy.ActiveWindow.Selection.WholeStory();
                    WordDocCopy.ActiveWindow.Selection.Copy();                WordAppPaste = new Microsoft.Office.Interop.Word.ApplicationClass();
                    WordDocPaste = WordAppPaste.Documents.Open(ref strPath, ref Nothing, ref Nothing, ref Nothing,
                                               ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                                               ref Nothing, ref Nothing, ref Nothing, ref Nothing,
                                               ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                    WordDocPaste.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA3;
                    WordDocPaste.ActiveWindow.Selection.Paste();
                    WordDocPaste.Save();
                }
                catch
                { }
                finally
                {
                    if (WordDocCopy != null)
                    {
                        Marshal.ReleaseComObject(WordDocCopy);
                        WordDocCopy = null;
                    }
                    WordAppCopy.NormalTemplate.Saved = true;
                    WordAppCopy.Quit(ref Nothing, ref Nothing, ref Nothing);                if (WordDocPaste != null)
                    {
                        Marshal.ReleaseComObject(WordDocPaste);
                        WordDocPaste = null;
                    }
                    WordAppPaste.NormalTemplate.Saved = true;
                    WordAppPaste.Quit(ref Nothing, ref Nothing, ref Nothing);
                }
            }
            #endregion