Open and modify Word Document

后端 未结 3 1783
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 19:26

I want to open a word file saved in my server using \"Microsoft.Office.Interop.Word\". This is my code:

    object missing = System.Reflection.Missing.Value;         


        
相关标签:
3条回答
  • 2020-12-05 19:41

    http://support.microsoft.com/kb/257757

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    http://freeword.codeplex.com/

    Document document = new Document();
    document.LoadFromFile("test.doct");
    
    0 讨论(0)
  • 2020-12-05 19:49

    first add the dll of office.interop by adding directly to the resources then add this using directive:

    using Microsoft.Office.Interop.Word;
    

    and use the following code

    Application ap = new Application();
    Document document = ap.Documents.Open(@"C:\invoice.docx");;
    
    0 讨论(0)
  • 2020-12-05 19:56

    You need to make sure that the Word application window actually is made visible when automating Word like that:

    var applicationWord = new Microsoft.Office.Interop.Word.Application();
    applicationWord.Visible = true;
    
    0 讨论(0)
提交回复
热议问题