|
-
March 16th, 2009, 03:22 PM
#1
[RESOLVED] How to load a word document into an RTB without getting wordapp an the screen ?
Hi friends !
I want to read a worddoc into a richtextbox but when I do it like the following
Code:
public void ReadWordStream(string path) {
ApplicationClass wordApp = new ApplicationClass();
object file = path;
object readOnly = false;
object isVisible = false;
object missing = System.Reflection.Missing.Value;
wordApp.WindowState = WdWindowState.wdWindowStateMinimize;
wordApp.Visible = false;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file, 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);
wordApp.Visible = false;
doc.ActiveWindow.Selection.WholeStory();
string text = doc.ActiveWindow.Selection.Text;
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
rtbDoc.Paste();
object boolObj = (object)false;
wordApp.Documents.Close(ref boolObj, ref boolObj, ref boolObj);
wordApp.Quit(ref boolObj, ref boolObj, ref boolObj);
}
The wordApplication opens and closes which looks terrible.
Is there a way to read out the text within formating to my RTB without opening the word Application. ( It's word 2003 ) As you can see I tried to minimize, I tried to get visible to false. Maybe there is a way to access the word document without opening word ?application
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
March 16th, 2009, 03:48 PM
#2
Re: How to load a word document into an RTB without getting wordapp an the screen ?
have you tried...
Code:
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
wordApp.Visible = false;
object file = @"c:\test.doc";
object readOnly = false;
object isVisible = false;
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file, 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);
wordApp.Visible = false;
doc.ActiveWindow.Selection.WholeStory();
string text = doc.ActiveWindow.Selection.Text;
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
rtbDoc.Paste();
object boolObj = (object)false;
doc.Close(ref boolObj, ref boolObj, ref boolObj);
wordApp.Quit(ref boolObj, ref boolObj, ref boolObj);
This worked for me. The first time I did see a flash but then I made a change the the bolded line and no flash. I think that would be the only line you might need to change.
-
March 16th, 2009, 06:45 PM
#3
Re: [RESOLVED] How to load a word document into an RTB without getting wordapp an the
Wooow. This small difference has cost me one day and was solved now within a few minutes
Really great help, I was really astonihed why this hasn't worked the way I wanted it to work
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|