Hello,
This would be the first time I've ever posted about a coding problem I have, usually I'm pretty good at researching the problem and finding my solutions but I'm at a loss now. My skills in programming have almost left me, so I guess you could deem me as a beginner for now till it comes back.
The problem:
I'm trying to create an embedded office document, that being excel into my windows form using the web browser control. Using this as a how to:
http://support.microsoft.com/?scid=kb%3Ben-us%3B304662&x=11&y=11[
^]
I can use a button event to open my file and the file will populate into my window. Now for my first problem though not as serious, I cannot figure out how to hide the Excel application. When my app opens the file into the web browser, Microsoft Excel still opens though it's blank with no workbook. I've tried many different methods to make this hidden, but I just can't seem to understand how the web browser is using the object, when I try to declare a new one it will compile fine but throws out an error when it gets used.
My second problem, once I can understand how to use this object that the web browser is using, or have to activate it into my own object, I need to be able to use the SaveAs(), I just can't save it because I'm unsure of what object is being used.
I appreciate any help, I haven't programmed in over a year so please bare with me, I may not understand too much lingo but I have no problems looking what you might have to say up to better understand it :) PS I'm using Office 2007 and running Windows 7
Sorry for the long post, hope I didn't leave anything out :cool:
~Nick
Here's my source code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
namespace TestIntegratedExcel
{
public partial class Form1 : Form
{
private Object oDocument;
String strFileName;
CSV_DAT csv_dat = new CSV_DAT("TestFile");
public Form1()
{
InitializeComponent();
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)
{
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
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)
{
openButton.Text = "Browse";
openFileDialog1.Filter = "Office Documents(*.xls, *.xlsx, *.csv)|*.xls;*.xlsx;*.csv";
openFileDialog1.FilterIndex = 1;
}
public void Form1_Closed(object sender, System.EventArgs e)
{
oDocument = null;
}
public void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
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);
}
private void clearButton_Click(object sender, EventArgs e)
{
axWebBrowser1.Navigate("about:blank");
strFileName = null;
}