S
Sirdots
Hi Everyone,
I have a C# windows application and will want to embed Microsoft word
on it(a form). I want to be able to use the spell checker and see the
squiggy lines if there is an error.
I have seen some samples where you have to use the openDialog to choose
a word document. I dont want this. I will prefer a click on a command
button to automatically open word within the web browser on my form.
Also, I want to have a dropdown menu below the button where users can
select templates for their word documents.
Do yu have any idea?
I just copied some parts of the code that are relevant.
Thanks.
public EmbedDots()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.axWebBrowser1.NavigateComplete2 += new
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2);
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);
}
private void button1_Click(object sender, System.EventArgs e)
{
String strFileName;
//Find the Office document.
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
//If the user does not cancel, open the document.
if(strFileName.Length != 0)
{
Object refmissing = System.Reflection.Missing.Value;
oDocument = null;
axWebBrowser1.Navigate(strFileName, ref refmissing , ref refmissing
, ref refmissing , ref refmissing);
}
}
public void Form1_Load(object sender, System.EventArgs e)
{
button1.Text = "Browse";
openFileDialog1.Filter = "Office Documents(*.doc, *.xls,
*.ppt)|*.doc;*.xls;*.ppt" ;
openFileDialog1.FilterIndex = 1;
}
public void Form1_Closed(object sender, System.EventArgs e)
{
oDocument = null;
}
public void axWebBrowser1_NavigateComplete2(object sender,
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
//Note: You can use the reference to the document object to
// automate the document server.
Object o = e.pDisp;
oDocument =
o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);
Object oApplication =
o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);
Object oName =
o.GetType().InvokeMember("Name",BindingFlags.GetProperty
,null,oApplication,null);
MessageBox.Show("File opened by: " + oName.ToString() );
}
I have a C# windows application and will want to embed Microsoft word
on it(a form). I want to be able to use the spell checker and see the
squiggy lines if there is an error.
I have seen some samples where you have to use the openDialog to choose
a word document. I dont want this. I will prefer a click on a command
button to automatically open word within the web browser on my form.
Also, I want to have a dropdown menu below the button where users can
select templates for their word documents.
Do yu have any idea?
I just copied some parts of the code that are relevant.
Thanks.
public EmbedDots()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.axWebBrowser1.NavigateComplete2 += new
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2);
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);
}
private void button1_Click(object sender, System.EventArgs e)
{
String strFileName;
//Find the Office document.
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
//If the user does not cancel, open the document.
if(strFileName.Length != 0)
{
Object refmissing = System.Reflection.Missing.Value;
oDocument = null;
axWebBrowser1.Navigate(strFileName, ref refmissing , ref refmissing
, ref refmissing , ref refmissing);
}
}
public void Form1_Load(object sender, System.EventArgs e)
{
button1.Text = "Browse";
openFileDialog1.Filter = "Office Documents(*.doc, *.xls,
*.ppt)|*.doc;*.xls;*.ppt" ;
openFileDialog1.FilterIndex = 1;
}
public void Form1_Closed(object sender, System.EventArgs e)
{
oDocument = null;
}
public void axWebBrowser1_NavigateComplete2(object sender,
AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
//Note: You can use the reference to the document object to
// automate the document server.
Object o = e.pDisp;
oDocument =
o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);
Object oApplication =
o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);
Object oName =
o.GetType().InvokeMember("Name",BindingFlags.GetProperty
,null,oApplication,null);
MessageBox.Show("File opened by: " + oName.ToString() );
}