Forms in C# with fields that offer full Excel & Word functionality

G

Guest

Hello,
I am looking for specific information and sample code on the following:
I would like to know how I can use Excel and Word within (!) my C#
application. I would like to create a form with fields that have full Word
and Exel functionality, e.g. where the user can enter formated text (Word)
and numbers&formulas. The fields' information should be stored in a
respective object variables and I should be able to save the data to a BLOB
field within the SQL database.
Any ideas as to how this would work? Thanks.
PS: I am using Visual Studio 2005 and MS Office 2003 & WinXP Prof. is
installed on every PC.
 
N

Nicholas Paldino [.NET/C# MVP]

Thomas,

There are a few ways to do this, but they are all hackney, or difficult.
There isn't a control in .NET which will be an active document host (which
is what you need for excel/word/office functionality).

The first is to make sure that the VB6 runtime is installed on the
target machine. If so, then you can import the active x OLE document
control (which is an active document host) and use that.

The second would be to code all the interfaces in order to make your
control an active document interface.

The last would be to use the WebBrowser control, as it is an active
document host, and then you can host the word/excel file in that.
 
G

Guest

Hello Nicholas,

thanks for your reply.

I have already tried various things. The OLE-embedding does not result in a
stable "application" as I don't have full control over the Excel-instance
that is used for the Excel-file in the OLE-field. Having an Excel-file opened
in a Webbrowser field creates the same issue. I.e., these methods do not open
a new instance of Excel, they use an existing one. Or, if they create a new
one, then this instance is also accessible on the desktop for display of
other sheets. If a user e.g. creates an error or pending state in one sheet,
then my application can not run its Excel-sheet anymore.

The light Excel Web-control would be great, but I do not know how I can
effectively move data to and from it.

On your second suggestion I am not clear as to what this implies. Would you
mind to provide me with more details on this?

Thanks

--
Thomas-VC


Nicholas Paldino said:
Thomas,

There are a few ways to do this, but they are all hackney, or difficult.
There isn't a control in .NET which will be an active document host (which
is what you need for excel/word/office functionality).

The first is to make sure that the VB6 runtime is installed on the
target machine. If so, then you can import the active x OLE document
control (which is an active document host) and use that.

The second would be to code all the interfaces in order to make your
control an active document interface.

The last would be to use the WebBrowser control, as it is an active
document host, and then you can host the word/excel file in that.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thomas-VC said:
Hello,
I am looking for specific information and sample code on the following:
I would like to know how I can use Excel and Word within (!) my C#
application. I would like to create a form with fields that have full Word
and Exel functionality, e.g. where the user can enter formated text (Word)
and numbers&formulas. The fields' information should be stored in a
respective object variables and I should be able to save the data to a
BLOB
field within the SQL database.
Any ideas as to how this would work? Thanks.
PS: I am using Visual Studio 2005 and MS Office 2003 & WinXP Prof. is
installed on every PC.
 
N

Nicholas Paldino [.NET/C# MVP]

Thomas,

Here is a link to some information on Active Document Containers in MFC:

Thomas-VC said:
Hello Nicholas,

thanks for your reply.

I have already tried various things. The OLE-embedding does not result in
a
stable "application" as I don't have full control over the Excel-instance
that is used for the Excel-file in the OLE-field. Having an Excel-file
opened
in a Webbrowser field creates the same issue. I.e., these methods do not
open
a new instance of Excel, they use an existing one. Or, if they create a
new
one, then this instance is also accessible on the desktop for display of
other sheets. If a user e.g. creates an error or pending state in one
sheet,
then my application can not run its Excel-sheet anymore.

The light Excel Web-control would be great, but I do not know how I can
effectively move data to and from it.

On your second suggestion I am not clear as to what this implies. Would
you
mind to provide me with more details on this?

Thanks

--
Thomas-VC


Nicholas Paldino said:
Thomas,

There are a few ways to do this, but they are all hackney, or
difficult.
There isn't a control in .NET which will be an active document host
(which
is what you need for excel/word/office functionality).

The first is to make sure that the VB6 runtime is installed on the
target machine. If so, then you can import the active x OLE document
control (which is an active document host) and use that.

The second would be to code all the interfaces in order to make your
control an active document interface.

The last would be to use the WebBrowser control, as it is an active
document host, and then you can host the word/excel file in that.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thomas-VC said:
Hello,
I am looking for specific information and sample code on the following:
I would like to know how I can use Excel and Word within (!) my C#
application. I would like to create a form with fields that have full
Word
and Exel functionality, e.g. where the user can enter formated text
(Word)
and numbers&formulas. The fields' information should be stored in a
respective object variables and I should be able to save the data to a
BLOB
field within the SQL database.
Any ideas as to how this would work? Thanks.
PS: I am using Visual Studio 2005 and MS Office 2003 & WinXP Prof. is
installed on every PC.
 
N

Nicholas Paldino [.NET/C# MVP]

Thomas,

Here is a link to information about Active Document Containers in MFC:

http://msdn2.microsoft.com/en-us/library/644x1yy6(VS.80).aspx

There is nothing in .NET for this, and I don't know that you want to use
unmanaged code. An active document container is that it simply (well, not
simply) implements a number of interfaces. Here is a discussion of the
requirements:

http://msdn2.microsoft.com/en-us/library/644x1yy6(VS.80).aspx#container_requirements

Now, you could probably do this in .NET, but it will be a lot of work (a
ton of interop).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thomas-VC said:
Hello Nicholas,

thanks for your reply.

I have already tried various things. The OLE-embedding does not result in
a
stable "application" as I don't have full control over the Excel-instance
that is used for the Excel-file in the OLE-field. Having an Excel-file
opened
in a Webbrowser field creates the same issue. I.e., these methods do not
open
a new instance of Excel, they use an existing one. Or, if they create a
new
one, then this instance is also accessible on the desktop for display of
other sheets. If a user e.g. creates an error or pending state in one
sheet,
then my application can not run its Excel-sheet anymore.

The light Excel Web-control would be great, but I do not know how I can
effectively move data to and from it.

On your second suggestion I am not clear as to what this implies. Would
you
mind to provide me with more details on this?

Thanks

--
Thomas-VC


Nicholas Paldino said:
Thomas,

There are a few ways to do this, but they are all hackney, or
difficult.
There isn't a control in .NET which will be an active document host
(which
is what you need for excel/word/office functionality).

The first is to make sure that the VB6 runtime is installed on the
target machine. If so, then you can import the active x OLE document
control (which is an active document host) and use that.

The second would be to code all the interfaces in order to make your
control an active document interface.

The last would be to use the WebBrowser control, as it is an active
document host, and then you can host the word/excel file in that.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thomas-VC said:
Hello,
I am looking for specific information and sample code on the following:
I would like to know how I can use Excel and Word within (!) my C#
application. I would like to create a form with fields that have full
Word
and Exel functionality, e.g. where the user can enter formated text
(Word)
and numbers&formulas. The fields' information should be stored in a
respective object variables and I should be able to save the data to a
BLOB
field within the SQL database.
Any ideas as to how this would work? Thanks.
PS: I am using Visual Studio 2005 and MS Office 2003 & WinXP Prof. is
installed on every PC.
 
B

Ben Voigt [C++ MVP]

Thomas-VC said:
Hello Nicholas,

thanks for your reply.

I have already tried various things. The OLE-embedding does not result in
a
stable "application" as I don't have full control over the Excel-instance
that is used for the Excel-file in the OLE-field. Having an Excel-file
opened
in a Webbrowser field creates the same issue. I.e., these methods do not
open
a new instance of Excel, they use an existing one. Or, if they create a
new
one, then this instance is also accessible on the desktop for display of
other sheets. If a user e.g. creates an error or pending state in one
sheet,
then my application can not run its Excel-sheet anymore.

That seems to be an inherent problem in Excel. If it opens multiple
documents in the same process instead of starting multiple processes, then
the state of one can affect the others. Not much you can do about that
unless you "trick" OLE into thinking Excel isn't running so it starts a new
copy. Not sure how the running object table works exactly, but perhaps you
can hook it so that your app doesn't share the running object table of the
rest of the system.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top