Exemple #1
0
        private void button7_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            object miss     = System.Reflection.Missing.Value;
            object path     = Application.StartupPath + "\\1.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 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();
            }
            MessageBox.Show(totaltext);
            docs.Close();
            word.Quit();


            label1.Text = "";
            openFileDialog1.InitialDirectory = Application.StartupPath;
            openFileDialog1.FileName         = null;
            openFileDialog1.Filter           = "Файлы txt(*.txt)|*.txt|Файлы doc(*.doc)|*.doc*|Файлы fb2(*.fb2)|*.fb2|Файлы epub(*.epub)|*.epub";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                OpenBook = openFileDialog1.FileName;
                Process process = new Process();
                process.StartInfo.FileName  = @OpenBook;
                process.StartInfo.Arguments = "";
                process.Start();
            }
        }
Exemple #2
0
        public void quit()
        {
            if (this.word == null)
            {
                return;
            }

            try
            {
                //Now use the Quit method to cleanup.
                //The Quit event will fire because saveChanges is set to wdDoNotSaveChanges.
                //If saveChanges were changed to wdSaveChanges, the Quit event will not fire.
                object saveChanges    = WdSaveOptions.wdDoNotSaveChanges;
                object originalFormat = Missing.Value;
                object routeDocument  = Missing.Value;
                word.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
                Thread.Sleep(2000);
            }
            catch { }
            this.word = null;
        }