473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Writting to Excel using a COM Add-In and C#

Hi everybody,

I have already opened a thread with the same question but since I got no
answers I will try to rephrase my question and be more specific.

- I have already build a COM Add-In following the Microsoft Q302901 article.
- This COM Add-in adds a button at the "Standard" Excel toolbar.
- When I press the button I want a value to be inserted on the current cell
of the active sheet.
- I want the add-in to user late-binding when talking to Excel, so no Excel
references are done in the project.

I am trying to achieve the above behaviour, by following the method bellow:

1. In the method OnConnection(), the application object, that comes as a
parameter, is stored on a private variable called applicationObject.
2. In the button_Click() event handling method, I inserted the following
code (using parts of the Microsoft article Q302902):

private void MyButton_Click(CommandBarButton cmdBarbutton,ref bool cancel)
{
// Get the active sheet.
object sheet = applicationObject.GetType().InvokeMember("ActiveSh eet",
BindingFlags.GetProperty, null, applicationObject, null);

// Get the range.
object range = sheet.GetType().InvokeMember("Range",
BindingFlags.GetProperty, null, sheet, new object[] {"A1", Missing.Value});

// Write the value
range.GetType().InvokeMember("Value", BindingFlags.SetProperty, null,
range, new object[] {"Hello world!"});
}

My problem is that although the first two invocations in the method (sheet
and range) work fine, the third one, that writes the value into the range,
throws an exception.

Can anyone tell me what is going wrong here ?

Why I can read but not write to properties ?

Please help...

Thanks

Emmanuel
Nov 16 '05 #1
0 1320

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Niyazi | last post by:
Hi, I have to retrieve a data from AS400 DB2 and after working with data I have to export into one of existing Excel file. I can connect into specific library in AS400 DB2 using AS400...
2
by: Krish | last post by:
This is my first attempt, please bear. I referenced Excel 10.0 Object from VS .NET IDE, I think this creates Interop Object for Excel. I have the following code. ------code start---- ...
3
by: Boris Condarco | last post by:
Hi gurus, I'm using excel 2000 to show data that comes from datagrid. The problem is that for any reason the asp.net application maintains the excel open, even though, i do close it. Besides,...
4
by: msnnews.msn.com | last post by:
hi there, i've got a form that populates a datagrid, and a button that calls a function to export to an excel file. All is well with the export, no errors are returned, but the Excel instance...
1
by: Steven | last post by:
Hello, I use the following code to make an Excel-file, which works fine with Excel 2003 (and the MS Excel 11.0 object library): Dim Excel As New Excel.Application Dim oBook As...
2
by: John Walker | last post by:
Hello, Below is my code for exporting a datagrid to Excel. It works fine, but we're hoping to format the output as well - setting the font size and type, and giving each column a specific width,...
4
by: jmalvika | last post by:
Hi all, I'm trying to generate an excel report from an ASP web page using .. "response.ContentType = "application/vnd.ms-excel" .... I need to add a custom header & footer to the excel...
9
by: Abhay | last post by:
How can i write a excel file through c program.?
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
5
by: wolfjmt | last post by:
Hi, I am trying to write to data to a .xlsx file. I can currently write the data to a .xls file. I tried to change the extension of the xls file (to xlsx) but Excel gave the following error:Excel...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.