ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hosting Excel in a WinForms application (https://www.excelbanter.com/excel-programming/328687-hosting-excel-winforms-application.html)

RNG

Hosting Excel in a WinForms application
 
Hello:

Is it possible to host Excel inside a .Net WinForms application?
My application dynamically generates an Excel workbook. I want to open
it, but don't want to launch Excel as a separate application, but rather I
want to open the workbook in a pop-up dialog from my WinForms application.

Thanks in advance!
Ram


Robin Hammond[_2_]

Hosting Excel in a WinForms application
 
Ram,

I'm not sure about .net issues but you should be able to use the Office Web
Components to embed a spreadsheet like control on a form.

Robin Hammond
www.enhanceddatasystems.com

"RNG" wrote in message
...
Hello:

Is it possible to host Excel inside a .Net WinForms application?
My application dynamically generates an Excel workbook. I want to open
it, but don't want to launch Excel as a separate application, but rather I
want to open the workbook in a pop-up dialog from my WinForms application.

Thanks in advance!
Ram




Peter Huang [MSFT]

Hosting Excel in a WinForms application
 
Hi

Thanks for your feedback!

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

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


Vincent Melia

Hosting Excel in a WinForms application
 
Is there a way to directly embed it in a Winform? It would also be great to
have the embedded Excel docs toolbars to merge with the Winforms toolbars
when activated.

I've tried a WebBrowser control but working with it was kludgy and obscure.

Any ideas?

""Peter Huang" [MSFT]" wrote:

Hi

From the OWC document, the spreadsheet did not have inside print. It is
printed when it is hosted in a web page. I think that is why it is called
Office Web Component. :)

Print a spreadsheet
To print a spreadsheet on a Web page, you must print the entire Web page.
¡¤ To print a spreadsheet from a design window, see Help in your
design program for specific instructions about printing a Web page.
¡¤ To print a spreadsheet from the browser, click Print on the
Microsoft Internet Explorer File menu.
Note If the spreadsheet is wider or longer than the printed page, the
areas that don't fit on the page are not printed. For more control over how
the data is printed, including the ability to print a long list and set
page breaks, you can export the spreadsheet to Microsoft Excel by clicking
Export to Microsoft Excel on the toolbar. For information about printing
from Excel, see Excel Help.

For your scenario, I think it is better to export the spreadsheet in xls
file and then print via Excel automation.

If you still have any concern, please feel free to post here.


Best regards,

Peter Huang
Microsoft Online Partner Support

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



Michel Pierron

Hosting Excel in a WinForms application
 
Hi Vincent,
amusing idea; why not in a userform ?
You can try in a userform module:

Option Explicit
Private Declare Function FindWindowA& Lib _
"user32" (ByVal lpClassName$, ByVal lpWindowName$)
Private Declare Function SetParent& Lib _
"user32" (ByVal hWndChild&, ByVal hWndNewParent&)
Private Declare Function SetWindowLongA& Lib _
"user32" (ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function MoveWindow& Lib _
"user32" (ByVal hwnd&, ByVal x&, ByVal y& _
, ByVal nWidth&, ByVal nHeight&, ByVal bRepaint&)

Private WithEvents oXL As Excel.Application
Private xlHwnd&, hwnd&

Private Sub UserForm_Activate()
DoEvents
oXL.Visible = True
SetParent xlHwnd, hwnd
SetWindowLongA xlHwnd, -16, &H140F0000
Call UserForm_Resize
oXL.Workbooks.Add
End Sub

Private Sub UserForm_Initialize()
Me.StartUpPosition = 3
hwnd = FindWindowA(vbNullString, Me.Caption)
SetWindowLongA hwnd, -16, &H84CC0080
Dim c As Object
Set oXL = New Excel.Application
oXL.Caption = "IsMine"
' Without CommandBars.
'For Each c In oXL.CommandBars
'If Not c.Name = "Cell" Then c.Enabled = False
'Next
xlHwnd = FindWindowA(vbNullString, "IsMine")
End Sub

Private Sub UserForm_QueryClose(Cancel%, CloseMode%)
On Error Resume Next
SetParent xlHwnd, 0
oXL.Visible = False
DoEvents
Me.Hide
DoEvents
Dim c As Object
For Each c In oXL.CommandBars
c.Enabled = True
Next
oXL.Quit
Set oXL = Nothing
End Sub

Private Sub UserForm_Resize()
Dim w!: w = Me.InsideWidth * 4 / 3
Dim h!: h = Me.InsideHeight * 4 / 3
MoveWindow xlHwnd, 0, 0, w, h, 1
End Sub

Regards,
MP

"Vincent Melia" a écrit dans le
message de news: ...
Is there a way to directly embed it in a Winform? It would also be great

to
have the embedded Excel docs toolbars to merge with the Winforms toolbars
when activated.

I've tried a WebBrowser control but working with it was kludgy and

obscure.

Any ideas?

""Peter Huang" [MSFT]" wrote:

Hi

From the OWC document, the spreadsheet did not have inside print. It is
printed when it is hosted in a web page. I think that is why it is

called
Office Web Component. :)

Print a spreadsheet
To print a spreadsheet on a Web page, you must print the entire Web

page.
¡¤ To print a spreadsheet from a design window, see Help in your
design program for specific instructions about printing a Web page.
¡¤ To print a spreadsheet from the browser, click Print on the
Microsoft Internet Explorer File menu.
Note If the spreadsheet is wider or longer than the printed page, the
areas that don't fit on the page are not printed. For more control over

how
the data is printed, including the ability to print a long list and set
page breaks, you can export the spreadsheet to Microsoft Excel by

clicking
Export to Microsoft Excel on the toolbar. For information about printing
from Excel, see Excel Help.

For your scenario, I think it is better to export the spreadsheet in xls
file and then print via Excel automation.

If you still have any concern, please feel free to post here.


Best regards,

Peter Huang
Microsoft Online Partner Support

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

rights.






All times are GMT +1. The time now is 12:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com