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


C# Microsoft.Office.Interop.Word.Application.Quit方法代码示例

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


在下文中一共展示了Microsoft.Office.Interop.Word.Application.Quit方法的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: 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

示例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: 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

示例6: btn_Read_Click

 private void btn_Read_Click(object sender, EventArgs e)
 {
     Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();//实例化Word对象
     Microsoft.Office.Interop.Word.Table table;//声明Word表格对象
     int P_int_TableCount = 0, P_int_Row = 0, P_int_Column = 0;//定义3个变量,分别用来存储表格数量、表格中的行数、列数
     string P_str_Content;//存储Word表格的单元格内容
     object missing = System.Reflection.Missing.Value;//获取缺少的object类型值
     string[] P_str_Names = txt_Word.Text.Split(',');//存储所有选择的Word文件名
     object P_obj_Name;//存储遍历到的Word文件名
     Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();//实例化Excel对象
     //打开指定的Excel文件
     Microsoft.Office.Interop.Excel.Workbook workbook = excel.Application.Workbooks.Open(txt_Excel.Text, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
     Microsoft.Office.Interop.Excel.Worksheet newWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets.Add(missing, missing, missing, missing);//创建新工作表
     for (int i = 0; i < P_str_Names.Length - 1; i++)//遍历所有选择Word文件名
     {
         P_obj_Name = P_str_Names[i];//记录遍历到的Word文件名
         //打开Word文档
         Microsoft.Office.Interop.Word.Document document = word.Documents.Open(ref P_obj_Name, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
         P_int_TableCount = document.Tables.Count;//获取Word文档中表格的数量
         if (P_int_TableCount > 0)//判断表格数量是否大于0
         {
             for (int j = 1; j <= P_int_TableCount; j++)//遍历所有表格
             {
                 table = document.Tables[j];//记录遍历到的表格
                 P_int_Row = table.Rows.Count;//获取表格行数
                 P_int_Column = table.Columns.Count;//获取表格列数
                 for (int row = 1; row <= P_int_Row; row++)//遍历表格中的行
                 {
                     for (int column = 1; column <= P_int_Column; column++)//遍历表格中的列
                     {
                         P_str_Content = table.Cell(row, column).Range.Text;//获取遍历到的单元格内容
                         newWorksheet.Cells[i + row, column] = P_str_Content.Substring(0, P_str_Content.Length - 2);//将遍历到的单元格内容添加到Excel单元格中
                     }
                 }
             }
         }
         else
         {
             if (P_int_Row == 0)//判断前面是否已经填充过表格
                 newWorksheet.Cells[i + P_int_Row + 1, 1] = document.Content.Text;//直接将Word文档内容添加到工作表中
             else
                 newWorksheet.Cells[i + P_int_Row, 1] = document.Content.Text;//直接将Word文档内容添加到工作表中
         }
         document.Close(ref missing, ref missing, ref missing);//关闭Word文档
     }
     excel.Application.DisplayAlerts = false;//不显示提示对话框
     workbook.Save();//保存工作表
     workbook.Close(false, missing, missing);//关闭工作表
     word.Quit(ref missing, ref missing, ref missing);//退出Word应用程序
     MessageBox.Show("已经成功将多个Word文档的内容合并到了Excel的同一个数据表中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
开发者ID:TGHGH,项目名称:C-1200,代码行数:51,代码来源:Frm_Main.cs

示例7: CreateDocument

        public void CreateDocument()
        {
            string filePath = Path.GetTempFileName() + ".docx";
            try
            {
                //Create an instance for word app
                winword = new Microsoft.Office.Interop.Word.Application();

                //Set animation status for word application
                //winword. ShowAnimation = false;

                //Set status for word application is to be visible or not.
                winword.Visible = false;

                //Create a new document
                document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing);

                this.PrintTree(ClasificacionSingleton.Clasificacion, 0);

                foreach (Microsoft.Office.Interop.Word.Section wordSection in document.Sections)
                {
                    Microsoft.Office.Interop.Word.Range footerRange = wordSection.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                    footerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdGray50;
                    footerRange.Font.Size = 12;
                    footerRange.Text = DateTimeUtilities.ToLongDateFormat(DateTime.Now);
                }

                //Save the document
                object filename = filePath;
                document.SaveAs2(ref filename);
                document.Close(ref missing, ref missing, ref missing);
                document = null;
                winword.Quit(ref missing, ref missing, ref missing);
                winword = null;
                MessageBox.Show("Estructura generada satisfactoriamente!");

                System.Diagnostics.Process.Start(filePath);
            }
            catch (Exception ex)
            {
                string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                ErrorUtilities.SetNewErrorMessage(ex, methodName + " Exception,PdfTreeStructure", "MateriasSGA");
            }
        }
开发者ID:danilozacyac,项目名称:MateriasSGACatalog,代码行数:44,代码来源:WordTreeStructure.cs

示例8: GetText

        public static string GetText(string filePath)
        {
            var rangeText = "ERROR: Failed to get text";

            var assembly = Assembly.GetExecutingAssembly();
            var binPath = System.IO.Path.GetDirectoryName(assembly.Location);

            var inputFile = Path.Combine(binPath, filePath);

            //  create & define filename object with temp.doc
            object inputDocFilename = inputFile;

            if (File.Exists((string)inputDocFilename))
            {
                object readOnly = false;
                object isVisible = false;

                //  create missing object
                object missing = Missing.Value;

                //  create Word application object
                var wordApp = new Microsoft.Office.Interop.Word.Application();

                wordApp.Visible = false;

                var inputDocument = wordApp.Documents.Open(ref inputDocFilename, 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);

                inputDocument.Activate();

                rangeText = inputDocument.Range().Text;

                inputDocument.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges);

                wordApp.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp);
            }

            return rangeText;
        }
开发者ID:runoplays,项目名称:Holoware,代码行数:43,代码来源:DocumentUtilities.cs

示例9: GetFileCount

 public void GetFileCount(string path,out int FileCount)
 {
     FileCount = 1;
     object tempFileName = path;
     FileInfo fi = new FileInfo(path);
     string astdt = fi.Extension;
     object strFileName = fi.Name;
     object flg = false;
     object oMissing = System.Reflection.Missing.Value;
     switch (astdt.ToLower())
     {
         case ".doc":
         case ".docx":
             astdt = "pdf";
             Microsoft.Office.Interop.Word._Application oWord;
             Microsoft.Office.Interop.Word._Document oDoc;
             oWord = new Microsoft.Office.Interop.Word.Application();
             //oWord.Visible = true;
             oDoc = oWord.Documents.Open(ref tempFileName,
             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);
             try
             {
                 // 计算Word文档页数
                 Microsoft.Office.Interop.Word.WdStatistic stat = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
                 FileCount = oDoc.ComputeStatistics(stat, ref oMissing);
                 return;
             }
             catch (Exception ex)
             {
                 if (oDoc == null) XLog.XTrace.WriteLine(ex.Message);
                 throw (ex);
             }
             finally
             {
                 oDoc.Close(ref flg, ref oMissing, ref oMissing);
                 oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
             }
         default:
             break;
     }
 }
开发者ID:kcly3027,项目名称:freePhoto,代码行数:43,代码来源:upimg.ashx.cs

示例10: SavePdf

        /// <summary>
        /// ファイルをPDF形式で保存
        /// </summary>
        public override void SavePdf()
        {
            Microsoft.Office.Interop.Word.Application word = null;
            Microsoft.Office.Interop.Word.Documents docs = null;
            Microsoft.Office.Interop.Word.Document d = null;

            try
            {
                //ファイルを取得
                object file = this.GetAbsolutePath();
                word = new Microsoft.Office.Interop.Word.Application();
                docs = word.Documents;
                d = docs.Open(file);

                d.ExportAsFixedFormat(this.GetPdfPath(),
                    Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF,
                    false,
                    Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint,
                    Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                if (d != null)
                {
                    d.Close();
                }
                if (word != null)
                {
                    word.Quit();
                }
            }
        }
开发者ID:Kazunori-Kimura,项目名称:office2pdf,代码行数:41,代码来源:Word.cs

示例11: ConvertDOCtoRTF

        /// <summary>
        /// The metod convert from DOC to RTF
        /// </summary>
        /// <param name="Source"> The source doc file </param>
        /// <returns> The target file path </returns>
        public static string ConvertDOCtoRTF(string sSource)
        {
            //Creating the instance of Word Application
            Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();

            // specifying the Source & Target file names
            object Source = sSource;
            object Target = Path.GetDirectoryName(sSource) + "\\" + Path.GetFileNameWithoutExtension(sSource) + ".TXT";

            // Use for the parameter whose type are not known or
            // say Missing
            object Unknown = Type.Missing;

            // Source document open here
            // Additional Parameters are not known so that are
            // set as a missing type
            newApp.Documents.Open(ref Source, ref Unknown,
                 ref Unknown, ref Unknown, ref Unknown,
                 ref Unknown, ref Unknown, ref Unknown,
                 ref Unknown, ref Unknown, ref Unknown,
                 ref Unknown, ref Unknown, ref Unknown, ref Unknown);

            // Specifying the format in which you want the output file
            object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatText;

            //Changing the format of the document
            newApp.ActiveDocument.SaveAs(ref Target, ref format,
                    ref Unknown, ref Unknown, ref Unknown,
                    ref Unknown, ref Unknown, ref Unknown,
                    ref Unknown, ref Unknown, ref Unknown,
                    ref Unknown, ref Unknown, ref Unknown,
                    ref Unknown, ref Unknown);

            // for closing the application
            newApp.Quit(ref Unknown, ref Unknown, ref Unknown);

            return (Target.ToString());
        }
开发者ID:GiladShoham,项目名称:RedRock,代码行数:43,代码来源:DocToRTF.cs

示例12: CreateWord

        public void CreateWord(String HtmlFile, string fileWord)
        {
            object filename1 = HtmlFile;

            object oMissing = System.Reflection.Missing.Value;

            object oFalse = false;

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

            Microsoft.Office.Interop.Word.Document oDoc = new
            Microsoft.Office.Interop.Word.Document();

            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref
            oMissing, ref oMissing);

            oWord.Visible = false;

            oDoc = oWord.Documents.Open(ref filename1, 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);

            filename1 = fileWord;

            object fileFormat =
            Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;

            oDoc.SaveAs(ref filename1, ref fileFormat, 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);

            oDoc.Close(ref oFalse, ref oMissing, ref oMissing);

            oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
        }
开发者ID:VadimDang,项目名称:Process_ebook,代码行数:38,代码来源:Form1.cs

示例13: DoIt

        public void DoIt()
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            app.Visible = false;

            int errors = 0;
            if (this.TextBoxSpell.Text.Length > 0)
            {
                object template = Type.Missing;
                object newTemplate = Type.Missing;
                object documentType = Type.Missing;
                object visible = true;

                Microsoft.Office.Interop.Word._Document doc1 = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                doc1.Words.First.InsertBefore(this.TextBoxSpell.Text);
                Microsoft.Office.Interop.Word.ProofreadingErrors spellErrorsColl = doc1.SpellingErrors;
                errors = spellErrorsColl.Count;

                object optional = Type.Missing;

                app.ActiveWindow.Activate();

                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;
                this.TextBoxSpell.Text = doc1.Range(ref first, ref last).Text;
            }

            object saveChanges = false;
            object originalFormat = Type.Missing;
            object routeDocument = Type.Missing;

            app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
        }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:37,代码来源:SpellCheckingTest.xaml.cs

示例14: PrintEnvelope

        public void PrintEnvelope(string line1, string line2, string line3)
        {
            line1 += "\n\n";
            line2 += "\n\n";
            line3 += "\n\n";

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

            Microsoft.Office.Interop.Word.Document doc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            object oAddress = line1 + line2 + line3;

            doc.Envelope.PrintOut(ref oMissing, ref oAddress, 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, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            while (oWord.BackgroundPrintingStatus.ToString() == "1")
            {
                //do nothing while waiting for printer to get moving
            }
            oWord.Quit(ref oFalse, ref oMissing, ref oMissing);
        }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:24,代码来源:Envelope.cs

示例15: btnUpload_Click

        private void btnUpload_Click(object sender, EventArgs e)
        {
            OpenFileDialog od = new OpenFileDialog();
            od.Filter = "Word Documents|*.docx|All Files|*.*";

            if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtFirstName.Text = "";
                txtLastName.Text = "";
                cboCategory.Text = "";
                cboPhoneNumber.Text = "";
                cboEmail.Text = "";
                txtJobTitle.Text = "";
                txtCompany.Text = "";
                txtCityState.Text = "";
                lstAdditionalFiles.Items.Clear();
                txtNote.Text = "";
                txtAdditionalFile.Text = "";

                Cursor = Cursors.WaitCursor;
                try
                {
                    //System.Diagnostics.Process.Start("app.exe", od.FileName);

                    Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
                    object miss = System.Reflection.Missing.Value;
                    object enc = Microsoft.Office.Core.MsoEncoding.msoEncodingEUCJapanese;
                    object path = od.FileName; //@"C:\Users\Administrator\Desktop\Les Tolbert.docx";
                    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 enc, 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();

                        Console.WriteLine(totaltext);
                    }
                    //System.IO.File.WriteAllText("tmp.txt", totaltext);
                    txtContents.Text = totaltext;
                    lstAdditionalFiles.Items.Add(od.FileName, true);

                    GetEmail(totaltext);
                    GetPhoneNumbers(totaltext);

                    string fullname = txtContents.Lines[1].Trim();
                    string[] names = fullname.Split(' ');
                    txtFirstName.Text = names[0];
                    txtLastName.Text = names[1];

                    //txtPhoneNumber.Text = txtContents.Lines[2];

                    txtCityState.Text = txtContents.Lines[3];

                    foreach (string item in txtContents.Lines)
                    {
                        if (item.ToLower().Contains("company"))
                        {
                            string cname = item.Substring(item.IndexOf("company") + 1, item.Length);
                            txtCompany.Text = cname;
                            break;
                        }
                    }

                    foreach (string item in txtContents.Lines)
                    {
                        if (item.ToLower().Contains("job title"))
                        {
                            string cname = item.Substring(item.IndexOf("job title") + 1, item.Length);
                            txtJobTitle.Text = cname;
                            break;
                        }
                    }

                    //txtAdditionalFile.Text = od.FileName;

                    // Console.WriteLine(totaltext);
                    docs.Close();
                    word.Quit();

                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Cursor = Cursors.Default;
                //txtContents.Text = System.IO.File.ReadAllText("tmp.txt");
            }
        }
开发者ID:RichardEby,项目名称:Pipelined,代码行数:90,代码来源:Form1.cs


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