当前位置: 首页>>代码示例>>C#>>正文


C# Word.Application类代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Word.Application的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.Application类的具体用法?C# Microsoft.Office.Interop.Word.Application怎么用?C# Microsoft.Office.Interop.Word.Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Microsoft.Office.Interop.Word.Application类属于命名空间,在下文中一共展示了Microsoft.Office.Interop.Word.Application类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: print

        /*Setting up a printable invoice for the required Customer
         */
        public void print()
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();

            Microsoft.Office.Interop.Word.Document doc = app.Documents.Add("E:/CarRentalSystem/Invoice.docx");

            doc.Variables["Name"].Value = lbl_Forename.Text + " " + lbl_Surname.Text;

            doc.Variables["Address"].Value = lbl_Address.Text;

            doc.Variables["Town"].Value = lbl_Town.Text;

            doc.Variables["County"].Value = lbl_County.Text;

            doc.Variables["Phone_No"].Value = lbl_Phone.Text;

            doc.Variables["Date"].Value = lbl_Date.Text;

            doc.Variables["Balance"].Value = lbl_Acc_Balance.Text;

            doc.Variables["Id"].Value =  lbl_Customer_Id.Text;
            doc.Fields.Update();

            doc.SaveAs2("E:/CarRentalSystem/Invoice.docx2");

            doc.PrintOut();

            doc.Close();

            app.Quit();
        }
开发者ID:pafennell,项目名称:SoftwareEngineering,代码行数:33,代码来源:IncomeAnalysis.cs

示例2: PrintReport

        public void PrintReport()
        {
            Microsoft.Office.Interop.Word.Application oWord;
            Object oMissing = System.Reflection.Missing.Value;
            Object oTrue = true;
            Object oFalse = false;

            oWord = new Microsoft.Office.Interop.Word.Application();
            oWord.Visible = false;

            string activePrinter = oWord.ActivePrinter;
            if (string.IsNullOrEmpty(this.m_PrinterName) == false)
            {
                oWord.ActivePrinter = m_PrinterName;
            }

            Object oFile = this.m_ReportSaveFileName;
            Microsoft.Office.Interop.Word.Document doc = oWord.Documents.Open(ref oFile, ref oMissing, ref oTrue,
                 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);

            doc.PageSetup.FirstPageTray = Microsoft.Office.Interop.Word.WdPaperTray.wdPrinterMiddleBin;

            doc.PrintOut(ref oFalse, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oFalse,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            oWord.ActivePrinter = activePrinter;
            oWord.Quit(ref oFalse, ref oMissing, ref oMissing);
        }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:30,代码来源:Report.cs

示例3: Button1_Click

    protected void Button1_Click(object sender, EventArgs e)
    {
        fileName = FileUpload1.PostedFile.FileName;
        myfullPath = Server.MapPath("Files/" + fileName);
        FileUpload1.SaveAs(Server.MapPath("Files/" + fileName));
        Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
        object miss = System.Reflection.Missing.Value;

        object path = Server.MapPath("Files/" + fileName);
        object readOnly = true;
        Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
        string totaltext = "";
        for (int i = 0; i < docs.Paragraphs.Count; i++)
        {
            totaltext += " \r\n " + docs.Paragraphs[i + 1].Range.Text.ToString();
        }

        PreviewTheoryTextBox.Text = totaltext;

        //kratao to onoma tou arxeiou doc se label pou den fainetai
        LabelToKeepFileName.Text = fileName;
        docs.Close();
        word.Quit();
        FileUpload1.Visible = false;
    }
开发者ID:ksksAsa,项目名称:aepTrain1,代码行数:25,代码来源:InsertTheory.aspx.cs

示例4: SaveDocAsXPS

        public static void SaveDocAsXPS(string fileName)
        {
            Microsoft.Office.Interop.Word.Application oWord;
            Object oMissing = System.Reflection.Missing.Value;
            Object oTrue = true;
            Object oFalse = false;

            oWord = new Microsoft.Office.Interop.Word.Application();
            oWord.Visible = false;

            string currentPrinter = oWord.ActivePrinter;
            oWord.ActivePrinter = "Microsoft XPS Document Writer";

            Object docFileName = fileName;
            Object xpsFileName = fileName.Replace(".doc", ".xps");

            Object fileFormat = "wdFormatDocument";

            if (System.IO.File.Exists(docFileName.ToString()) == true)
            {
                Microsoft.Office.Interop.Word.Document doc = oWord.Documents.Open(ref docFileName, 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);

                object oOutputFile = xpsFileName;
                doc.PrintOut(ref oFalse, ref oFalse, ref oMissing, ref oOutputFile, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                    ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            }

            oWord.ActivePrinter = currentPrinter;
            oWord.Quit(ref oFalse, ref oMissing, ref oMissing);
        }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:32,代码来源:FileConversionHelper.cs

示例5: Main

        static void Main(string[] args)
        {
            //using Word = Microsoft.Office.Interop.Word;

            object fileName = Path.Combine(@"D:\VS2010Workspace\WordDocReplaceTest\WordDocReplaceTest\bin\Release", "TestDoc.docx");
            object missing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = false };

            Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);

            aDoc.Activate();

            Microsoft.Office.Interop.Word.Find fnd = wordApp.ActiveWindow.Selection.Find;

            fnd.ClearFormatting();
            fnd.Replacement.ClearFormatting();
            fnd.Forward = true;
            fnd.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;

            fnd.Text = "{替换前内容}";
            fnd.Replacement.Text = "替换后内容-updated";

            fnd.Execute(Replace: Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll);
            aDoc.Save();

            aDoc.Close(ref missing, ref missing, ref missing);
            wordApp.Quit(ref missing, ref missing, ref missing);
        }
开发者ID:Alexenix,项目名称:UtilityTools,代码行数:28,代码来源:Program.cs

示例6: RevisarOrtografia

        private static string RevisarOrtografia(string texto)
        {
            var app = new Microsoft.Office.Interop.Word.Application();
            string corregido = string.Empty;
            if (!String.IsNullOrEmpty(texto))
            {
                app.Visible = false;
                object template = Missing.Value;
                object newTemplate = Missing.Value;
                object documentType = Missing.Value;
                object visible = false;

                Microsoft.Office.Interop.Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate,
                                                                                 ref documentType, ref visible);
                doc1.Words.First.InsertBefore(texto);
                object optional = Missing.Value;
                doc1.CheckSpelling(
                    ref optional, ref optional, ref optional, ref optional, ref optional, ref optional,
                    ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);

                object first = 0;
                object last = doc1.Characters.Count - 1;
                corregido = doc1.Range(ref first, ref last).Text;
            }
            object saveChanges = false;
            object originalFormat = Missing.Value;
            object routeDocument = Missing.Value;
            app.Application.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
            return corregido;
        }
开发者ID:joelgasso,项目名称:blogcodes,代码行数:30,代码来源:Form1.cs

示例7: CreateAWord

        public void CreateAWord()
        {
            //实例化word应用对象
            this._wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
            Object myNothing = System.Reflection.Missing.Value;

            this._wordDocument = this._wordApplication.Documents.Add(ref myNothing, ref myNothing, ref myNothing, ref myNothing);
        }
开发者ID:shady32,项目名称:WordMaker,代码行数:8,代码来源:WordMacker.cs

示例8: SpellCheck

        public SpellCheck()
        {
            this.m_WordApp =  new Microsoft.Office.Interop.Word.Application();
            this.m_WordApp.Visible = false;
            this.m_WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oTrue);

            InitializeComponent();
        }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:8,代码来源:SpellCheck.xaml.cs

示例9: WordApplication

 private WordApplication()
 {
     this.m_WordApp = new Microsoft.Office.Interop.Word.Application();
     this.m_WordApp.Visible = false;
     this.m_Documents = this.m_WordApp.Documents;
     this.m_Document = this.m_Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oTrue);
     this.m_WordSuggestionList = new List<string>();
 }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:8,代码来源:WordApplication.cs

示例10: OpenFile

        void OpenFile(string filepath, int selectionstart)
        {
            cache["lastdir"] = Path.GetDirectoryName(filepath);
            string fileext = Path.GetExtension(filepath).ToLower();
            if (fileext == ".doc" || fileext == ".docx")
            {
                object oMissing = System.Reflection.Missing.Value;
                object isReadOnly = true;
                Microsoft.Office.Interop.Word._Application oWord;
                Microsoft.Office.Interop.Word._Document oDoc;

                oWord = new Microsoft.Office.Interop.Word.Application();
                oWord.Visible = false;
                object fileName = filepath;
                oDoc = oWord.Documents.Open(ref fileName,
                ref oMissing, ref isReadOnly, 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);

                this.rtbxMain.Text = oDoc.Content.Text;
                oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
                if (MessageBox.Show("转换为RTF文档并重新打开?", "转换格式", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    string newrtfpath = filepath + ".rtf";
                    this.rtbxMain.SaveFile(newrtfpath, RichTextBoxStreamType.RichText);
                    MessageBox.Show("转换为rtf成功.\r\n保存位置:" + newrtfpath, "转换格式");
                    OpenFile(newrtfpath, selectionstart);
                    return;
                }
            }
            else
            {
                FileStream fs = File.Open(filepath, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs, Encoding.Default, true);

                if (fileext == ".rtf")
                {
                    this.rtbxMain.Rtf = sr.ReadToEnd();
                    this.rtbxMain.Font = new Font("微软雅黑", 14f);
                }
                else
                {
                    rtbxMain.Text = sr.ReadToEnd();
                }
                sr.Close();
                fs.Close();
                fs.Dispose();
                sr.Dispose();
            }
            rtbxMain.SelectionStart = selectionstart;
            currentfilepath = filepath;
            this.Text = Path.GetFileNameWithoutExtension(currentfilepath);
            this.Icon = ((System.Drawing.Icon)(new System.ComponentModel.ComponentResourceManager(typeof(MainForm)).GetObject("$this.Icon")));
            tsmiReplaceWindowsTitle.Text = "隐藏标题";
            this.tsmiCurrentFilename.Text = this.Text;
            this.notifyIcon1.Text = this.Text;
        }
开发者ID:Natsuwind,项目名称:DeepInSummer,代码行数:58,代码来源:MainForm.cs

示例11: OpenDocument

        public static DocumentWrapper OpenDocument(String path)
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();

            DocumentWrapper wrapper = new DocumentWrapper();
            wrapper.Application = app;
            wrapper.Document = app.Documents.Open(path);

            return wrapper;
        }
开发者ID:tojoirinah,项目名称:Refonte-Recueil-One,代码行数:10,代码来源:MSWordInteropHelper.cs

示例12: Initialize

 protected override void Initialize() {
     base.Initialize();
     this.Application = this.GetHostItem<Microsoft.Office.Interop.Word.Application>(typeof(Microsoft.Office.Interop.Word.Application), "Application");
     Globals.ThisAddIn = this;
     global::System.Windows.Forms.Application.EnableVisualStyles();
     this.InitializeCachedData();
     this.InitializeControls();
     this.InitializeComponents();
     this.InitializeData();
 }
开发者ID:bovender,项目名称:VstoAddinInstaller,代码行数:10,代码来源:ThisAddIn.Designer.cs

示例13: Dispose

 public void Dispose()
 {
     this._wordApplication.Quit();
     System.Runtime.InteropServices.Marshal.ReleaseComObject(this._wordApplication);
     System.Runtime.InteropServices.Marshal.ReleaseComObject(this._wordDocument);
     this._wordApplication = null;
     this._wordDocument = null;
     GC.Collect();
     GC.Collect();
 }
开发者ID:shady32,项目名称:WordMaker,代码行数:10,代码来源:WordMacker.cs

示例14: DoInteropDemo

 public static String DoInteropDemo(String filePath)
 {
     var wordApp = new Microsoft.Office.Interop.Word.Application();
     Microsoft.Office.Interop.Word.Document doc =
         wordApp.Documents.Open(filePath, ReadOnly: true);
     dynamic docProperties = doc.BuiltInDocumentProperties;
     string authorName = docProperties["Author"].Value;
     doc.Close(SaveChanges: false);
     return authorName;
 }
开发者ID:alainlompo,项目名称:csharp-warmup-samples,代码行数:10,代码来源:SimpleWordInterop.cs

示例15: OnConnection

        /// <summary>
        /// Implements the OnConnection method of the IDTExtensibility2 interface.
        /// Receives notification that the Add-in is being loaded.
        /// </summary>
        /// <param name="application">Root object of the host application.</param>
        /// <param name="connectMode"> Describes how the Add-in is being loaded.</param>
        /// <param name="addInInst">Object representing this Add-in.</param>
        /// <param name="custom"></param>
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _application = (Application) application;
            _presenter = new ApplicationPresenter(_application);
            _addInInstance = addInInst;

            if (connectMode != ext_ConnectMode.ext_cm_Startup)
            {
                OnStartupComplete(ref custom);
            }
        }
开发者ID:Dmdv,项目名称:InwordRemover,代码行数:19,代码来源:Connect.cs


注:本文中的Microsoft.Office.Interop.Word.Application类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。