Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Embed Excel in form with Windows.Forms.WebBrowser then save file

173 views
Skip to first unread message

sippyuconn

unread,
Dec 20, 2006, 8:38:01 AM12/20/06
to
Hi

My goal is to embed an Excel Worksheet in a form and then save that work
sheet.
I want to use Windows.Forms.WebBrowser because it comes with Framework v2.0
and that will definitely be on my target machines

I can embed the worksheet on a form with Windows.Forms.WebBrowser but have
found no way to save. I use this to load the file
Browser.Url = new Uri(sFile.xls);

Anyone know how load browser.document with the xls and then save it???


If i use the Office webBrowser I am to use this to save after I load into a
browser.document
axWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_SAVE,SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, null,null)


From some reading I could save thru Browser.

Peter Huang [MSFT]

unread,
Dec 21, 2006, 2:05:13 AM12/21/06
to
Hi

The .NET FW 2.0 WebBrowser is a wrapper for WebBrowser ActiveX Control, but
it did not wrap it completely.
e.g. it wrap the save in the method below, but did not provide further
customize
webBrowser1.ShowSaveAsDialog();

We still can get the previous webbrowser interface by
webBrowser1.ActiveXInstance, but to use it explicitly we have to add
reference to the COM WebBrowser control.

But we still can do it via reflection, this way we did not need to add
reference to the COM WebBrowser control.

NOTE: the OLECMDID.OLECMDID_SAVE const definition is just an integer, we
can pass the int directly to define the value by ourselves.

public enum OLECMDID
{
OLECMDID_OPEN = 1,
OLECMDID_NEW = 2,
OLECMDID_SAVE = 3,
OLECMDID_SAVEAS = 4,
OLECMDID_SAVECOPYAS = 5,
OLECMDID_PRINT = 6,
OLECMDID_PRINTPREVIEW = 7,
OLECMDID_PAGESETUP = 8,
OLECMDID_SPELL = 9,
OLECMDID_PROPERTIES = 10,
OLECMDID_CUT = 11,
OLECMDID_COPY = 12,
OLECMDID_PASTE = 13,
OLECMDID_PASTESPECIAL = 14,
OLECMDID_UNDO = 15,
OLECMDID_REDO = 16,
OLECMDID_SELECTALL = 17,
OLECMDID_CLEARSELECTION = 18,
OLECMDID_ZOOM = 19,
OLECMDID_GETZOOMRANGE = 20,
OLECMDID_UPDATECOMMANDS = 21,
OLECMDID_REFRESH = 22,
OLECMDID_STOP = 23,
OLECMDID_HIDETOOLBARS = 24,
OLECMDID_SETPROGRESSMAX = 25,
OLECMDID_SETPROGRESSPOS = 26,
OLECMDID_SETPROGRESSTEXT = 27,
OLECMDID_SETTITLE = 28,
OLECMDID_SETDOWNLOADSTATE = 29,
OLECMDID_STOPDOWNLOAD = 30,
OLECMDID_ONTOOLBARACTIVATED = 31,
OLECMDID_FIND = 32,
OLECMDID_DELETE = 33,
OLECMDID_HTTPEQUIV = 34,
OLECMDID_HTTPEQUIV_DONE = 35,
OLECMDID_ENABLE_INTERACTION = 36,
OLECMDID_ONUNLOAD = 37,
OLECMDID_PROPERTYBAG2 = 38,
OLECMDID_PREREFRESH = 39,
OLECMDID_SHOWSCRIPTERROR = 40,
OLECMDID_SHOWMESSAGE = 41,
OLECMDID_SHOWFIND = 42,
OLECMDID_SHOWPAGESETUP = 43,
OLECMDID_SHOWPRINT = 44,
OLECMDID_CLOSE = 45,
OLECMDID_ALLOWUILESSSAVEAS = 46,
OLECMDID_DONTDOWNLOADCSS = 47,
OLECMDID_UPDATEPAGESTATUS = 48,
OLECMDID_PRINT2 = 49,
OLECMDID_PRINTPREVIEW2 = 50,
OLECMDID_SETPRINTTEMPLATE = 51,
OLECMDID_GETPRINTTEMPLATE = 52,
OLECMDID_PAGEACTIONBLOCKED = 55,
OLECMDID_PAGEACTIONUIQUERY = 56,
OLECMDID_FOCUSVIEWCONTROLS = 57,
OLECMDID_FOCUSVIEWCONTROLSQUERY = 58,
OLECMDID_SHOWPAGEACTIONMENU = 59,
OLECMDID_ADDTRAVELENTRY = 60,
OLECMDID_UPDATETRAVELENTRY = 61,
OLECMDID_UPDATEBACKFORWARDSTATE = 62,
OLECMDID_OPTICAL_ZOOM = 63,
OLECMDID_OPTICAL_GETZOOMRANGE = 64,
OLECMDID_WINDOWSTATECHANGED = 65,
}
public enum OLECMDEXECOPT
{
OLECMDEXECOPT_DODEFAULT = 0,
OLECMDEXECOPT_PROMPTUSER = 1,
OLECMDEXECOPT_DONTPROMPTUSER = 2,
OLECMDEXECOPT_SHOWHELP = 3,
}
private void button1_Click_1(object sender, EventArgs e)
{
//this.webBrowser1.ShowSaveAsDialog();

object o = System.Reflection.Missing.Value;
Type wb = this.webBrowser1.ActiveXInstance.GetType();

wb.InvokeMember("ExecWB",BindingFlags.InvokeMethod,null,webBrowser1.ActiveXI
nstance,new object[]{OLECMDID.OLECMDID_SAVE,
OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, o,o});
//SHDocVw.IWebBrowser2 pWB = this.webBrowser1.ActiveXInstance
as SHDocVw.IWebBrowser2;
//pWB.ExecWB(SHDocVw.OLECMDID.OLECMDID_SAVE,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref o,ref o);

}

Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

sippyuconn

unread,
Dec 21, 2006, 11:43:01 AM12/21/06
to
Peter

Thanks alot for the info - that was really helpful

1 question could you explain this code - it works - just trying to
understand what is happening


Type wb = this.webBrowser1.ActiveXInstance.GetType();
-When you set a type object with GetTYpe() what is happening??
Are you casting an object??
What objects can you do a GetTYpe() on??


wb.InvokeMember("ExecWB",BindingFlags.InvokeMethod,null,webBrowser1.ActiveXI
nstance,new object[]{OLECMDID.OLECMDID_SAVE,
OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, o,o});

-InvokeMember - what is that doings? Invoking a member method of that object?
How would I know that methos is available to use thru an InvokeMember???

Thanks Again

Peter Huang [MSFT]

unread,
Dec 25, 2006, 12:08:03 AM12/25/06
to
Hi,

Comments in line.

Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Thread-Topic: Embed Excel in form with Windows.Forms.WebBrowser then save
fi
| thread-index: AcclHxPg12REkFICSn2P6efCqrD7XA==
| X-WBNR-Posting-Host: 192.43.235.23
| From: =?Utf-8?B?c2lwcHl1Y29ubg==?= <sippy...@newsgroup.nospam>
| References: <886A30AE-B7E3-459A...@microsoft.com>
<b24uj5MJ...@TK2MSFTNGHUB02.phx.gbl>
| Subject: RE: Embed Excel in form with Windows.Forms.WebBrowser then save
fi
| Date: Thu, 21 Dec 2006 08:43:01 -0800
| Lines: 145
| Message-ID: <91D49A1C-E1F8-4C04...@microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2757
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.languages.csharp:5198
| NNTP-Posting-Host: tk2msftsbfm01.phx.gbl 10.40.244.148
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp


|
| Peter
|
| Thanks alot for the info - that was really helpful
|
| 1 question could you explain this code - it works - just trying to
| understand what is happening
|
|
| Type wb = this.webBrowser1.ActiveXInstance.GetType();
| -When you set a type object with GetTYpe() what is happening??
| Are you casting an object??
| What objects can you do a GetTYpe() on??
|

.NET is a type based programming language. Any .NET class/object is of an
type. In this way, CLR will provide rich type related information for us to
use in the runtime.
The program unit is Type, even int is a .NET Type. You may call get type on
it.
So the GetType() will tell us what is the Type of currently object?
Commonly it should be the class name of the .NET class.

This is not a casting.

Any .NET object/class can call GetType() method.You can consider it is a
class in C#, and all the .NET object is of certian class.

You may refer to the books below about the idea about .NET language.
Essential .NET, Volume I: The Common Language Runtime (Paperback)
by Don Box

CLR via C#, Second Edition (Paperback)
by Jeffrey Richter

|
|
wb.InvokeMember("ExecWB",BindingFlags.InvokeMethod,null,webBrowser1.ActiveXI
| nstance,new object[]{OLECMDID.OLECMDID_SAVE,
| OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, o,o});
|
| -InvokeMember - what is that doings? Invoking a member method of that
object?
| How would I know that methos is available to use thru an InvokeMember???
|

.NET provided a mechanism called reflection, which let us dynamically call
a method/ even create an object when we have the type information of the
object.
e.g. in the code above the string "ExecWB" can be replaced by other method
of webbrowser.

We are invoke member of object webBrowser1.ActiveXInstance oject.

In every .NET type, it have a method table which have the information of
all the methods of the object, so the .NET runtime will try to match the
method ExecWB in the type method table, once match, just call it.

You may get the information of Don box's book above.
Also here is good start about the reflection in .NET.
.NET Framework Developer's Guide
Reflection
http://msdn2.microsoft.com/en-us/library/cxz4wk15.aspx

| Thanks Again
|
|

0 new messages