Hi.
I'm new to c# .net programming, coming from a java background, and am
currently self learning the language trying to prepare a demo of a
windows.forms application of our current java client.
I've yet to undergo a training course, so im not sure if what i'm doing is
correct or not.
I'll post the code below, but what I'm trying to do is launch word documents
populating them with information which is returned to the windows form.
The Word.ApplicationClass object is expected to be available whilst the
client runs and can have many word documents attached.
Ive implemented this object as a static reference.
Ive added the word9.0 com object library reference to my project.
I can launch the word document fine, and have access to the interface and
able to modify the document. But, if I manually close the opened document.
Then re-execute the code to open another word doc, an
InteropServices.COMException is thrown.
with errors:
System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is
unavailable.
at Word.ApplicationClass.get_Documents()
It seems any reference to Word.ApplicationClass.Documents throws this error
after Ive closed the first opened document.
Ive tried creating a new Word.ApplicationClass object (instead of using the
static object) each time to create a new document and the same problem
persists.
Ive had a google around and the only article i found which resembles this
problem was in MS Article ID : 188546.
It suggested creating a temp word application class first, then closing it,
then creating a new class to launch the document from.
This didnt work either, but I think that this article isnt the same problem
which I experience.
Id really like to know whether this can be done successfully as its a big
draw to our business that this type of letter functionality is possible with
our client gui.
Any help would be greatly appreciated.
below is the code i have used using the static reference:
in our main class:
public static Word.ApplicationClass s_wordApp = new Word.ApplicationClass();
method to retrieve word application:
public static Word.ApplicationClass getWordApp()
{
return s_wordApp;
}
calling code to launch a word doc:
private void m_btnLetter_Click(object sender, System.EventArgs e)
{
// Set up all the parameters as generic objects so we can pass them in
Documents.Add
object missing = System.Reflection.Missing.Value;
object fileName = "normal.dot"; // template file name
object newTemplate = false;
object docType = 0;
object isVisible = true;
object visibleFalse = false;
// Create a new Document, by calling the Add function in the Documents
collection
Word.Document aDoc = null;
try
{
aDoc = Form1.getWordApp().Documents.Add(ref fileName, ref newTemplate, ref
docType,
ref isVisible);
// need to see the created document, so make it visible
Form1.getWordApp().Visible = true;
aDoc.Activate();
Form1.getWordApp().Selection.ParagraphFormat.Alignment =
Word.WdParagraphAlignment.wdAlignParagraphCenter;
// Toggle the title to a Bold Font
Form1.getWordApp().Selection.Font.Bold = (int)Word.WdConstants.wdToggle;
// Type the Text of the Title that was inputted by the user in the Custom
Dialog
string str = "text to be input to doc: " + m_txtSomeText.Text + ", more
text: " + m_txtSomeText1.Text;
object start = 0;
object end = 0;
Word.Range rng = aDoc.Range(ref start, ref end);
rng.Text = str;
}
catch (System.Runtime.InteropServices.COMException)
{
}
}
lee - 30 Mar 2005 09:33 GMT
anyone????
> Hi.
> I'm new to c# .net programming, coming from a java background, and am
[quoted text clipped - 97 lines]
>
> }