//Add a reference to the Microsoft Word 11.0 object library in the project reference private void button1_Click(object sender, System.EventArgs e) { //Call the open file dialog box Get the file WORD file, RTF file, text file path name to be opened OpenFileDialog opd = new OpenFileDialog(); opd.InitialDirectory = "c:\\"; opd.Filter = "Word document (*.doc)|*.doc|Text document (*.txt)|*.txt|RTF document (*.rtf)|*.rtf|All documents (*.*)|*.*"; opd.FilterIndex = 1; if (opd.ShowDialog() == DialogResult.OK && opd.FileName.Length > 0) { //Create an instance of the Word class, disadvantage: cannot be correct Read the display of tables, pictures, etc. Word.ApplicationClass app = new Word.ApplicationClass(); Word.Document doc = null; object missing = System.Reflection.Missing.Value; object FileName = opd.FileName; object readOnly = false; object isVisible = true; object index = 0; try { doc = app.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); doc.ActiveWindow.Selection.WholeStory(); doc.ActiveWindow.Selection.Copy(); //Get data from the clipboard IDataObject data=Clipboard.GetDataObject(); this.richTextBox1.Text=data.GetData(DataFormats.Text).ToString(); } finally { if (doc != null) { doc.Close(ref missing, ref missing, ref missing); doc = null; } if (app != null) { app.Quit(ref missing, ref missing, ref missing); app = null;[Page] } } } }
But, what if we use javascript to open it? Actually, it's not difficult. 2. Open the word document in javascript We create a new html file and write a FileUpLoad and button control.
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn