• 大小: 235KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: 其他
  • 标签: word  c#  自动生成  

资源简介

通过vsto自动生成word文档,通过dot自动生成word文档、插入数据;解决启动多word进程冲突问题

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;


namespace NmdsyCooperationManagement.GenerateWord
{
    public class CCWordApp
    {
        private static Microsoft.Office.Interop.Word.ApplicationClass oWordApplic=new ApplicationClass(); // a reference to Word application
        private Microsoft.Office.Interop.Word._Document oDoc; // a reference to the document


        public CCWordApp()
        {
           
            // activate the interface with the COM object of Microsoft Word
          //  oWordApplic = new  Microsoft.Office.Interop.Word.ApplicationClass();
        }

        // Open a file (the file must exists) and activate it
        public void Open(string strFileName)
        {
            object fileName = strFileName;
            object readOnly = false;
            object isVisible = true;
            object missing = System.Reflection.Missing.Value;
            oDoc = oWordApplic.Application.Documents.Add(ref fileName ref missing ref missing ref missing);
            //oDoc = oWordApplic.Documents.Open(ref fileName ref missing ref readOnly
            //    ref missing ref missing ref missing ref missing ref missing ref missing
            //    ref missing ref missing ref isVisible ref missing ref missing ref missing ref missing);

            //oDoc.Activate();
        }


        // Open a new document
        public void Open()
        {
            object missing = System.Reflection.Missing.Value;
            oDoc = oWordApplic.Documents.Add(ref missing ref missing ref missing ref missing);

            //oDoc.Activate();
        }
        public void InsertBookmarkText(string bookmarknamestring text)
        {
            object missing = System.Reflection.Missing.Value;

            object Bookmark = (int)Microsoft.Office.Interop.Word.WdGoToItem.wdGoToBookmark;
            object NameBookMark = bookmarkname;
           //Bookmark bm= oDoc.Bookmarks.get_Item(ref NameBookMark) as  Bookmark;
           //bm.Select();
           //bm.Select();
            oDoc.GoTo(ref Bookmark ref missing ref missing ref NameBookMark).Text = text;
            // oDoc.GoTo(ref Bookmark ref missing ref missing ref NameBookMark);
           // oWordApplic.Selection.GoTo(ref Bookmark ref missing ref missing ref NameBookMark);
            

        }




        public void Quit()
        {
            object missing = System.Reflection.Missing.Value;
            object SaveChange = Microsoft.Office.Interop.Word.WdSaveOptions.wdSaveChanges;
            oDoc.Close(ref SaveChange ref missing ref missing);
             //oWordApplic.Application.
           // oWordApplic.Quit(ref missing ref missing ref missing);
            //oWordApplic.Quit(ref missing ref missing ref missing);
            
            //oWordApplic.Applicat

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     662120  2007-10-10 09:48  NmdsyCooperationManagement.GenerateWord\bin\Debug\Microsoft.Office.Interop.Word.dll

     文件      64088  2007-10-10 09:48  NmdsyCooperationManagement.GenerateWord\bin\Debug\Microsoft.Vbe.Interop.dll

     文件       8704  2009-10-22 15:14  NmdsyCooperationManagement.GenerateWord\bin\Debug\NmdsyCooperationManagement.GenerateWord.dll

     文件      22016  2009-10-22 15:14  NmdsyCooperationManagement.GenerateWord\bin\Debug\NmdsyCooperationManagement.GenerateWord.pdb

     文件     223800  2007-10-10 09:48  NmdsyCooperationManagement.GenerateWord\bin\Debug\Office.dll

     文件      13197  2009-10-22 15:14  NmdsyCooperationManagement.GenerateWord\CCWordApp.cs

     文件        266  2009-10-21 10:27  NmdsyCooperationManagement.GenerateWord\mssccprj.scc

     文件       2938  2009-10-21 14:09  NmdsyCooperationManagement.GenerateWord\NmdsyCooperationManagement.GenerateWord.csproj

     文件        305  2009-10-20 17:39  NmdsyCooperationManagement.GenerateWord\NmdsyCooperationManagement.GenerateWord.csproj.vspscc

     文件       1366  2009-10-21 14:32  NmdsyCooperationManagement.GenerateWord\obj\Debug\NmdsyCooperationManagement.GenerateWord.csproj.FileListAbsolute.txt

     文件       8704  2009-10-22 15:14  NmdsyCooperationManagement.GenerateWord\obj\Debug\NmdsyCooperationManagement.GenerateWord.dll

     文件      22016  2009-10-22 15:14  NmdsyCooperationManagement.GenerateWord\obj\Debug\NmdsyCooperationManagement.GenerateWord.pdb

     文件       4096  2009-10-20 14:40  NmdsyCooperationManagement.GenerateWord\obj\Debug\Refactor\NmdsyCooperationManagement.GenerateWord.dll

     文件       8821  2009-10-22 09:02  NmdsyCooperationManagement.GenerateWord\obj\Debug\ResolveAssemblyReference.cache

     文件       1470  2009-10-20 11:26  NmdsyCooperationManagement.GenerateWord\Properties\AssemblyInfo.cs

    ....SHR       176  2009-10-20 17:39  NmdsyCooperationManagement.GenerateWord\Properties\vssver2.scc

    ....SHR       295  2009-10-22 15:19  NmdsyCooperationManagement.GenerateWord\vssver2.scc

     文件       3606  2009-10-21 17:35  NmdsyCooperationManagement.GenerateWord\WordApp.cs

     目录          0  2009-10-20 14:40  NmdsyCooperationManagement.GenerateWord\obj\Debug\Refactor

     目录          0  2009-10-20 11:26  NmdsyCooperationManagement.GenerateWord\obj\Debug\TempPE

     目录          0  2009-10-21 14:32  NmdsyCooperationManagement.GenerateWord\bin\Debug

     目录          0  2009-10-22 15:14  NmdsyCooperationManagement.GenerateWord\obj\Debug

     目录          0  2009-10-20 11:52  NmdsyCooperationManagement.GenerateWord\bin

     目录          0  2009-10-20 11:26  NmdsyCooperationManagement.GenerateWord\obj

     目录          0  2009-10-20 17:39  NmdsyCooperationManagement.GenerateWord\Properties

     目录          0  2009-10-22 15:14  NmdsyCooperationManagement.GenerateWord

----------- ---------  ---------- -----  ----

              1047984                    26


评论

共有 条评论