C# tricks: Copy text from microsoft word in c#

U can’t access Microsoft doc file as u access a normal text file. For accessing a Microsoft doc file u have to add below dll as reference

u need to add reference from microsoft word object library 12.00 or 14.00
using Microsoft.Office.Core;
using Microsoft.Office.Interop;

now opening a doc file
//open msword in 2003
object fileName ="wordfile.doc";
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.ApplicationClass oWordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); //create a object
//open the file
Microsoft.Office.Interop.Word.Document oWordDoc = oWordApp.Documents.Open2002(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);
oWordDoc.Activate();
oWordApp.Visible = true;
oWordApp.Selection.TypeParagraph();
oWordDoc.Save();
oWordDoc.ActiveWindow.Selection.WholeStory();
oWordDoc.ActiveWindow.Selection.Copy();
TextBox1.Text = oWordDoc.Content.Text ; //show the text in textbox
oWordApp.Application.Quit(ref missing, ref missing, ref missing); //copy the text

hope this will help.

Advertisements

About kishor datta gupta

Graduate Research Assistant at University of Memphis Software Engineer at Silicon Orchard LTD. Former Research Assistant at Lamar University Former Software Engineer at Samsung R&D Institute Bangladesh Studies Ph.D. Computer Science at University of Memphis Studied Masters of Science in Computer Sciences at Lamar University Studied BSC in CSE at Khulna University of Engineering and Technology Studied HSC (completed) at Chittagang college 04-06 Studied High school at ST. Placid's High School'04 Studied Junior Secondary School at Saint Mary's School Lives in Memphis, Tennessee
This entry was posted in C# and tagged , , , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s