Reference C# object from within Excel

  • Thread starter Thread starter frankplank
  • Start date Start date
F

frankplank

Hi *,
I'm wondering if it is possible to create a C# object, and reference it
*explicitly* in an excel document. I imagine this will be more
possible if I programmatically populate the excel sheet cells, but I
would like to avoid this. I'm thinking something like this:

object1:
DataArray[][] ...;
GetValue(StringVal) ; // get value of data array, based on string

then within excel, I have cell references:
=object1.GetValue(StringValA)

----------------------------------

Also, if this is possible, I wonder how I trigger the creation of the
object's data values, which would be read from a delimited file.

Thanks very much,
Frank
 
Frank,

Do you mean you want to connect to a running instance of a .NET object,
or you want to create a .NET object in Excel? If the answer is the latter,
then you can access most .NET objects through COM interop. Check out the
section of the .NET documentation titled "Exposing .NET Framework Components
to COM", located at (watch for line wrap):

http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconadvancedcominterop.asp

If the answer is the former, you might want to use a web service (a bit
of overkill), or a serviced component (COM+).

Hope this helps.
 
Hi Nicholas,
Thanks for your response. I would say I am interested more in the
latter. To put it briefly, I'm in a situation where I have an existing
automated reporting (excel based) system that pulls it's source data
from a delimited file into a worksheet. The references (for
calculations, charts, etc.) within the worksheet are all dependent on
the cell position in excel, which is all dependent on the format of the
delimited file. So, when the file format changes, all the references
need to be shifted by 1 (or more)manually.

My idea is to put a middle layer (.net object) that reads the delimited
file, internally maps the values by a more useful type, and then
exposes the data structure to a callable function to the worksheet. So
instead of referencing (for example) =C1, I would use
=GetVal("TotalRevenuesWeek2").

Originally, I was hoping to programmatically populate the whole excel
workbook through C#, but specifying the chart looked rather ghastly.

Thanks, Frank
Frank,

Do you mean you want to connect to a running instance of a .NET object,
or you want to create a .NET object in Excel? If the answer is the latter,
then you can access most .NET objects through COM interop. Check out the
section of the .NET documentation titled "Exposing .NET Framework Components
to COM", located at (watch for line wrap):

http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconadvancedcominterop.asp

If the answer is the former, you might want to use a web service (a bit
of overkill), or a serviced component (COM+).

Hope this helps.


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

frankplank said:
Hi *,
I'm wondering if it is possible to create a C# object, and reference it
*explicitly* in an excel document. I imagine this will be more
possible if I programmatically populate the excel sheet cells, but I
would like to avoid this. I'm thinking something like this:

object1:
DataArray[][] ...;
GetValue(StringVal) ; // get value of data array, based on string

then within excel, I have cell references:
=object1.GetValue(StringValA)

----------------------------------

Also, if this is possible, I wonder how I trigger the creation of the
object's data values, which would be read from a delimited file.

Thanks very much,
Frank
 
Hi

I think you want to know about Automation Add-ins.
http://www.codeproject.com/dotnet/excelnetauto.asp

Best Regards,
Fredrik


frankplank said:
Hi Nicholas,
Thanks for your response. I would say I am interested more in the
latter. To put it briefly, I'm in a situation where I have an existing
automated reporting (excel based) system that pulls it's source data
from a delimited file into a worksheet. The references (for
calculations, charts, etc.) within the worksheet are all dependent on
the cell position in excel, which is all dependent on the format of the
delimited file. So, when the file format changes, all the references
need to be shifted by 1 (or more)manually.

My idea is to put a middle layer (.net object) that reads the delimited
file, internally maps the values by a more useful type, and then
exposes the data structure to a callable function to the worksheet. So
instead of referencing (for example) =C1, I would use
=GetVal("TotalRevenuesWeek2").

Originally, I was hoping to programmatically populate the whole excel
workbook through C#, but specifying the chart looked rather ghastly.

Thanks, Frank
Frank,

Do you mean you want to connect to a running instance of a .NET object,
or you want to create a .NET object in Excel? If the answer is the latter,
then you can access most .NET objects through COM interop. Check out the
section of the .NET documentation titled "Exposing .NET Framework Components
to COM", located at (watch for line wrap):
http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconadvancedcominterop.asp
If the answer is the former, you might want to use a web service (a bit
of overkill), or a serviced component (COM+).

Hope this helps.


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

frankplank said:
Hi *,
I'm wondering if it is possible to create a C# object, and reference it
*explicitly* in an excel document. I imagine this will be more
possible if I programmatically populate the excel sheet cells, but I
would like to avoid this. I'm thinking something like this:

object1:
DataArray[][] ...;
GetValue(StringVal) ; // get value of data array, based on string

then within excel, I have cell references:
=object1.GetValue(StringValA)

----------------------------------

Also, if this is possible, I wonder how I trigger the creation of the
object's data values, which would be read from a delimited file.

Thanks very much,
Frank
 
Hello,
Thanks for your response. Can automation add-ins be used on Excel
2002, for Windows 2000 ? This article suggests it is only available
for 2002 on XP. Thanks, Frank
Fredrik said:
Hi

I think you want to know about Automation Add-ins.
http://www.codeproject.com/dotnet/excelnetauto.asp

Best Regards,
Fredrik


frankplank said:
Hi Nicholas,
Thanks for your response. I would say I am interested more in the
latter. To put it briefly, I'm in a situation where I have an existing
automated reporting (excel based) system that pulls it's source data
from a delimited file into a worksheet. The references (for
calculations, charts, etc.) within the worksheet are all dependent on
the cell position in excel, which is all dependent on the format of the
delimited file. So, when the file format changes, all the references
need to be shifted by 1 (or more)manually.

My idea is to put a middle layer (.net object) that reads the delimited
file, internally maps the values by a more useful type, and then
exposes the data structure to a callable function to the worksheet. So
instead of referencing (for example) =C1, I would use
=GetVal("TotalRevenuesWeek2").

Originally, I was hoping to programmatically populate the whole excel
workbook through C#, but specifying the chart looked rather ghastly.

Thanks, Frank
..NET
object, the
latter, out
the
http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconadvancedcominterop.asp
If the answer is the former, you might want to use a web
service
(a bit
of overkill), or a serviced component (COM+).

Hope this helps.


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

Hi *,
I'm wondering if it is possible to create a C# object, and reference it
*explicitly* in an excel document. I imagine this will be more
possible if I programmatically populate the excel sheet cells,
but
I
would like to avoid this. I'm thinking something like this:

object1:
DataArray[][] ...;
GetValue(StringVal) ; // get value of data array, based on string

then within excel, I have cell references:
=object1.GetValue(StringValA)
of
the
object's data values, which would be read from a delimited file.

Thanks very much,
Frank
 
Yes. Only the version of Excel matters.

/Fredrik

frankplank said:
Hello,
Thanks for your response. Can automation add-ins be used on Excel
2002, for Windows 2000 ? This article suggests it is only available
for 2002 on XP. Thanks, Frank
Fredrik said:
Hi

I think you want to know about Automation Add-ins.
http://www.codeproject.com/dotnet/excelnetauto.asp

Best Regards,
Fredrik


frankplank said:
Hi Nicholas,
Thanks for your response. I would say I am interested more in the
latter. To put it briefly, I'm in a situation where I have an existing
automated reporting (excel based) system that pulls it's source data
from a delimited file into a worksheet. The references (for
calculations, charts, etc.) within the worksheet are all dependent on
the cell position in excel, which is all dependent on the format of the
delimited file. So, when the file format changes, all the references
need to be shifted by 1 (or more)manually.

My idea is to put a middle layer (.net object) that reads the delimited
file, internally maps the values by a more useful type, and then
exposes the data structure to a callable function to the worksheet. So
instead of referencing (for example) =C1, I would use
=GetVal("TotalRevenuesWeek2").

Originally, I was hoping to programmatically populate the whole excel
workbook through C#, but specifying the chart looked rather ghastly.

Thanks, Frank

Nicholas Paldino [.NET/C# MVP] wrote:
Frank,

Do you mean you want to connect to a running instance of a .NET
object,
or you want to create a .NET object in Excel? If the answer is the
latter,
then you can access most .NET objects through COM interop. Check out
the
section of the .NET documentation titled "Exposing .NET Framework
Components
to COM", located at (watch for line wrap):
http://msdn.microsoft.com/library/d...n-us/cpguide/html/cpconadvancedcominterop.asp
If the answer is the former, you might want to use a web service
(a bit
of overkill), or a serviced component (COM+).

Hope this helps.


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

Hi *,
I'm wondering if it is possible to create a C# object, and
reference it
*explicitly* in an excel document. I imagine this will be more
possible if I programmatically populate the excel sheet cells, but
I
would like to avoid this. I'm thinking something like this:

object1:
DataArray[][] ...;
GetValue(StringVal) ; // get value of data array, based on
string

then within excel, I have cell references:
=object1.GetValue(StringValA)

----------------------------------

Also, if this is possible, I wonder how I trigger the creation of
the
object's data values, which would be read from a delimited file.

Thanks very much,
Frank
 
Back
Top