| | |
Reading word file
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
Very easy...
Project->Add Reference->COM
tab and look for the Microsoft Word X.x Object Library
Use ApplicationClass class. Enjoy...
Project->Add Reference->COM
tab and look for the Microsoft Word X.x Object Library
Use ApplicationClass class. Enjoy...
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
No, I need you to try using it, I could tell you some code and your problem been solved! but I need you to try to learn. Please try
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
•
•
Join Date: Jan 2009
Posts: 68
Reputation:
Solved Threads: 0
Is there a way I could run it in background. i.e. without opening the word file.
Have manage to read the contents but it one can certainly notice the opening and closing of the world doc
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object fileNameO = fileName;//"c:\\sample.doc";
object objFalse = false;
object objTrue = true;
object missing = System.Reflection.Missing.Value;
object emptyData = string.Empty;
try
{
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileNameO, ref objFalse, ref objTrue,
ref objFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref objTrue,
ref missing, ref missing, ref missing, ref missing);
aDoc.ActiveWindow.Selection.WholeStory();
aDoc.ActiveWindow.Selection.Copy();
IDataObject data = System.Windows.Forms.Clipboard.GetDataObject();
String filetext = data.GetData(System.Windows.Forms.DataFormats.Text).ToString();
System.Windows.Forms.Clipboard.SetDataObject(string.Empty);
richTextBox1.Text = filetext;
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
wordApp.Documents.Close(ref missing, ref missing, ref missing);
wordApp.Application.Quit(ref missing, ref missing, ref missing);
}
}
Have manage to read the contents but it one can certainly notice the opening and closing of the world doc
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object fileNameO = fileName;//"c:\\sample.doc";
object objFalse = false;
object objTrue = true;
object missing = System.Reflection.Missing.Value;
object emptyData = string.Empty;
try
{
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileNameO, ref objFalse, ref objTrue,
ref objFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref objTrue,
ref missing, ref missing, ref missing, ref missing);
aDoc.ActiveWindow.Selection.WholeStory();
aDoc.ActiveWindow.Selection.Copy();
IDataObject data = System.Windows.Forms.Clipboard.GetDataObject();
String filetext = data.GetData(System.Windows.Forms.DataFormats.Text).ToString();
System.Windows.Forms.Clipboard.SetDataObject(string.Empty);
richTextBox1.Text = filetext;
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
finally
{
wordApp.Documents.Close(ref missing, ref missing, ref missing);
wordApp.Application.Quit(ref missing, ref missing, ref missing);
}
}
Look .doc file is binary file I think you can't do that without word, but .docx is follow OOXML you can play with it.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
- Easy help: Start and stop reading in the middle of a file (C++)
- Reading Document file (ASP.NET)
- search word in file (C++)
- Is it possible to arange lines in a file alphabetically? (C)
- Reading pascal file and searching for a particular word in that file (Pascal and Delphi)
- C++ File I/O (C++)
- Reading in a text file string is not complete (Pascal and Delphi)
- Reading from a file question (Python)
Other Threads in the C# Forum
- Previous Thread: Copying a File to a specific Directory on multiple Computers
- Next Thread: Create a PHPBB3 Forum Topic from a C# application.
| Thread Tools | Search this Thread |
.net access algorithm app application array bitmap box c# check checkbox client color combo combobox concurrency control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset datatable date/time datetime degrees dll draganddrop drawing enabled encryption enum excel file filename files finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization gtk image input install installer java list localization math microsoftc#visualexpress mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remoting richtextbox save server sleep socket sql sql-server statistics string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser webcam wia winforms wpf xml






