blah blah blah is here! blah blah » Close

up0down
link

I'm trying to use the Office XP COm Introp Assemblies to do this in sharpDevelop and i am having quite a few difficulties and all the examples i've seen haven't worked.
I have referenced the Office XP Com Introp Assemblies correctly but this is what i get:
...
using Word = Microsoft.Office.Interop.Word;
...
private Word.ApplicationClass WordApp = new Word.ApplicationClass();
...
public static Cv ReadBinaryToMemory(string filename){
Cv cv = new Cv();

object fileName = Globals.FileDirectory + filename;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
WordApp.Visible = true;
Word.Document aDoc = WordApp.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);
aDoc.Activate();
WordApp.Selection.TypeText("Copyright C# Corner");
WordApp.Selection.TypeParagraph();
return cv;
}

last answered 2 years ago

1 answers

up0down
link

That's as far as i get. To test it i complied this code and got a
denotes a 'field' where a 'class' was expectd error on all the lines that start with WordApp
Any help would be great cheers.
bazza

up0down
link

If i could just automate saving the word doc as a text file i could just use a streamReader and my program will work fine.
Any ideas guy/girls???
I need help
lots of help
please
i'm on my knees

up0down
link

So you need to be able to save it to a text file so that you can read it in using a stream reader? If that's what you want then you may want to use the SaveFileDialog function.
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = "z:\\";
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.DefaultExt = "*.txt*";
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.Dispose();
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
input code here }

up0down
link

I've got this to read the text
****Start Code****
Microsoft.Office.Interop.Word.Application wap = new Microsoft.Office.Interop.Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
object fileName = @"C:\Documents and Settings\Alan\My Documents\Borland Studio Projects\OfficeXPTest\Files\";
object objFalse = false;
object objTrue = true;
Microsoft.Office.Interop.Word.Document wdoc = wap.Documents.Open(ref fileName,ref missing,ref missing,
ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
wdoc.ActiveWindow.Selection.WholeStory();
wdoc.ActiveWindow.Selection.Copy();
//wap.Visible = true;
System.Windows.Forms.IDataObject data = System.Windows.Forms.Clipboard.GetDataObject();
string newString = data.GetData(System.Windows.Forms.DataFormats.Text).ToString();
Console.Write(newString);
****End Code*****
And i have referenced the Office XP Primary Interop Assemblies
It complies fine, but when i run the code i get this error:
Microsoft (R) Common Language Runtime Test Debugger Shell Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
(cordbg) a 0x978
Process 2424/0x978 created.
Warning: couldn't load symbols for c:\windows\microsoft.net\framework\v1.1.4322\
mscorlib.dll
Warning: couldn't load symbols for c:\windows\assembly\gac\microsoft.office.inte
rop.word\10.0.4504.0__31bf3856ad364e35\microsoft.office.interop.word.dll
Warning: couldn't load symbols for c:\windows\assembly\gac\system.windows.forms\
1.0.5000.0__b77a5c561934e089\system.windows.forms.dll
[thread 0xfa8] Thread created.
[thread 0xf6c] Thread created.
[thread 0xfa8] Unhandled exception generated: (0x050d53f0) <System.Runtime.Inter
opServices.COMException>
_className=<null>
_exceptionMethod=<null>
_exceptionMethodString=<null>
_message=(0x050d54f4) "COM object with CLSID {000209FF-0000-0000-C000-00000000
0046} is either not valid or not registered."
_innerException=<null>
_helpURL=<null>
_stackTrace=(0x050d55cc) array with dims=[12]
_stackTraceString=<null>
_remoteStackTraceString=<null>
_remoteStackIndex=0x00000000
_HResult=0x80040154
_source=<null>
_xptrs=0x00000000
_xcode=0xe0434f4d
018: Microsoft.Office.Interop.Word.Application wap = new Micr
osoft.Office.Interop.Word.ApplicationClass();
(cordbg)
Can anyone help, please??

up0down
link

I ran a trace and it is crashing on this line:
Microsoft.Office.Interop.Word.Application wap = new Microsoft.Office.Interop.Word.ApplicationClass();
???

up0down
link

Try using this to read from the document.
http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=400
Hope this helps

up0down
link

Hey blister that would work fine if i was reding text files, but if you tried that on a word document you would get a lot of crap on the end of the file. I tried messing around with your saving as a text file idea, but no sucess.
I know this code work as someone has used it with success and i know i have to use the Office XP Primary interop assemblies.
But thanks anyway

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback