This code describes how to read microsoft word file using c#
using System; using System.Collections.Generic; using System.Windows.Forms; using Microsoft.Office.Interop; using System.Reflection;
namespace ReadWordFile { class Program {
[STAThread] static void Main() { Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); object file = "C:\\local\\mywordfile.doc"; // Specify path for word file object nullobj = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj); doc.ActiveWindow.Selection.WholeStory(); doc.ActiveWindow.Selection.Copy(); IDataObject data = Clipboard.GetDataObject(); string allText = data.GetData(DataFormats.Text).ToString(); doc.Close(ref nullobj, ref nullobj, ref nullobj); wordApp.Quit(ref nullobj, ref nullobj, ref nullobj); Console.WriteLine(allText);
} } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|