I'm trying to use excel automation (from visual c# .NET) to fill data in a
range by using arrays. I am using Microsoft's Knowledge Base Article 302096
as a reference and using the example listed there, but I'm having trouble
with the following code:
**************** Code Starts Here ***********
Excel.Application m_objExcel;
Excel.Workbooks m_objBooks;
Excel._Workbook m_objBook;
Excel.Sheets m_objSheets;
Excel._Worksheet m_objSheet;
Excel.Range m_objRange;
m_objExcel = new Excel.Application();
m_objExcel.Visible = true;
m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
m_objBook = (Excel._Workbook)m_objBooks.Add(Missing.Value);
m_objSheets = (Excel.Sheets)m_objBook.Worksheets;
m_objSheet = (Excel._Worksheet)(m_objSheets.get_Item(1));
m_objRange = m_objSheet.get_Range("A1", Missing.Value);
m_objRange = m_objRange.get_Resize(5, 5);
double[,] doubleGrid = new double[5,5];
for (int row = 0; row < 5; row++)
{
for (int column = 0; column < 5; column++)
{
doubleGrid[row,column] = row * column;
}
}
m_objRange.set_Value(Missing.Value, doubleGrid);
*************** Code Ends Here *************
Microsoft Excel opens up okay, but then the server throws an exception (in
excel). I'm not able to figure out what the problem is, but I have a feeling
that it's something with Range.set_Value method.
Any ideas??
Thanks.
Mansi 3 3457
"Mansi" schrieb I'm trying to use excel automation (from visual c# .NET) to fill data in a range by using arrays. I am using Microsoft's Knowledge Base Article 302096 as a reference and using the example listed there, but I'm having trouble with the following code:
<Code snipped>
Microsoft Excel opens up okay, but then the server throws an exception (in excel). I'm not able to figure out what the problem is, but I have a feeling that it's something with Range.set_Value method.
Hi Mansi,
I just copied your code into a new project and it worked without problems on
my machine
(Excel 2003, PIAs installed, .NET Framework 1.1 [no SP1], WinXP SP2).
Can you give us more details about the exception?
Which version of Excel are you using? PIAs installed?
Cheers
Arne Janning
Here are the details of what I have installed:
(Excel 2003, PIAs have been installed, .NET Framework 1.1 [not sure about
SP1], WinXP SP2)
Here are more details about the exception (contents of Exception object):
(1) Exception.Message = "The server threw an exception"
(2) Exception.Source = "mscorlib"
This exception is generated after running the Range.set_Value method.
What other Exception properties would be helpful for you to determine the
cause of the error?
Thanks for trying this out.
Mansi
"Arne Janning" wrote: "Mansi" schrieb I'm trying to use excel automation (from visual c# .NET) to fill data in a range by using arrays. I am using Microsoft's Knowledge Base Article 302096 as a reference and using the example listed there, but I'm having trouble with the following code:
<Code snipped>
Microsoft Excel opens up okay, but then the server throws an exception (in excel). I'm not able to figure out what the problem is, but I have a feeling that it's something with Range.set_Value method.
Hi Mansi,
I just copied your code into a new project and it worked without problems on my machine (Excel 2003, PIAs installed, .NET Framework 1.1 [no SP1], WinXP SP2).
Can you give us more details about the exception?
Which version of Excel are you using? PIAs installed?
Cheers
Arne Janning
Hi Arne,
I just tried modifying the following declaration:
double[,] doubleGrid = new double[5,5]; to
object[,] doubleGrid = new object[5,5];
This seemed to solve my problem. Then I changed the declaration back to the
original, double[,] doubleGrid = new double[5,5]. I was expecting that I
would get the earlier error again. But it still worked okay. I'm not sure
what's going on???
What's the root cause of this funny behavior? I'm concerned that I'll run
into a similar situation again and not now how to debug it.
Thanks for all the help.
Mansi
"Mansi" wrote: Here are the details of what I have installed: (Excel 2003, PIAs have been installed, .NET Framework 1.1 [not sure about SP1], WinXP SP2)
Here are more details about the exception (contents of Exception object): (1) Exception.Message = "The server threw an exception" (2) Exception.Source = "mscorlib"
This exception is generated after running the Range.set_Value method.
What other Exception properties would be helpful for you to determine the cause of the error?
Thanks for trying this out.
Mansi
"Arne Janning" wrote:
"Mansi" schrieb I'm trying to use excel automation (from visual c# .NET) to fill data in a range by using arrays. I am using Microsoft's Knowledge Base Article 302096 as a reference and using the example listed there, but I'm having trouble with the following code:
<Code snipped>
Microsoft Excel opens up okay, but then the server throws an exception (in excel). I'm not able to figure out what the problem is, but I have a feeling that it's something with Range.set_Value method.
Hi Mansi,
I just copied your code into a new project and it worked without problems on my machine (Excel 2003, PIAs installed, .NET Framework 1.1 [no SP1], WinXP SP2).
Can you give us more details about the exception?
Which version of Excel are you using? PIAs installed?
Cheers
Arne Janning This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mark Day |
last post by:
Hi All,
I am using Access 2000 to generate over 40 Excel charts and pivot tables
using early binding to the Excel 9.0 object library. I am finding that if I
show the Excel object while processing...
|
by: taylor.bryant |
last post by:
I am running:
Win XP SP2
Excel 2002, Access 2002 (Office XP SP3)
Using Visual Basic (not VB.NET)
At one point (prior to XP SP2?!? - I can't pin it down), this did
not happen and I was easily...
|
by: Mansi |
last post by:
I need to do some research on how to use excel automation from c#. Does
anyone know of any good books related to this subject?
Thanks.
Mansi
|
by: Stephen Brooker |
last post by:
Hi all,
Just playing around a MS how-to sample to work with an Excel file from
within C#. Everything is fine and I understand it OK, however when Excel
and the application are closed, there is...
|
by: D. Shane Fowlkes |
last post by:
This most likely belongs in another forum but I thought I'd start here. I
have a COM Object written in VB6. The DLL will access MS Excel and use it's
Object Library to write a customized report...
|
by: a.theil |
last post by:
Please help!
I need a simple excel automation, just 2 write some files into excel.
I do:
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As...
|
by: Mark Rae |
last post by:
Hi,
My client has asked me to provide a "quick and dirty" way to export the
contents of a DataGrid to both Excel for analysis and Word for editing and
printing, so I'm investigating client-side...
|
by: Gunawan |
last post by:
Dear All,
I have create an excel (COM Object) using this code
Excel.Application xls = new Excel.Application();
but I can not remove it from memory although I have using close and quit
...
|
by: Keith Wilby |
last post by:
How controllable from Access VBA is Excel? I'm currently using automation
to dump 2 columns of data into an Excel spreadsheet so that the end user can
create a line graph based on it. Could the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |