473,568 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

efficient / easy way to convert an Excel.Range to a double[,]

Somewhat I remember I used to be able to do sth like the the following

double[,] values = (double[,])excel_range.Va lue2

But it seems to be not working any more, throwing an exception "cannot
convert System.Object[,] to System.Double[,]"

Of course, I can do iteration and, as a bottom line, using
Double.Parse(ce ll_value.ToStri ng()). The question is there a more
efficient way to do the job?

I am using Office XP with PIA.

Thanks.
Dec 17 '07 #1
4 2886
Just to make it clearer, the emphasis is how to convert multiple cells
in a ranger efficiently (e.g. in one call)

Dec 18 '07 #2
While I don't have the environment to do the C# stuff in Excel -
value2 returns a jagged array
So, this should work

double[][] values = (double[][])excel_range.Va lue2

Does this help?

Kalpesh
Dec 18 '07 #3
On Dec 18, 1:39 am, Kalpesh <shahkalp...@gm ail.comwrote:
While I don't have the environment to do the C# stuff in Excel -
value2 returns a jagged array
So, this should work

double[][] values = (double[][])excel_range.Va lue2

Does this help?

Kalpesh
No,unfortunatel y this does not work. In C#, it seems that Value2
returns a Object[,] instead of a jagged array.
Dec 18 '07 #4
This works well.
When transferring data from object[,] to double[,] - use copy method &
specify length of the array.
In this case it is 4 (2 rows, 2 columns)

See the code below for example.

object[,] data = new object[2,2];
data[0,0] = 0.5d;
data[0,1] = 1.5d;
data[1,0] = 2.0d;
data[1,1] = 5.5d;

double[,] ddata = new double[2,2];
Array.Copy(data , ddata, 4);
Console.WriteLi ne("ok");
ddata[0,0] = 3.5;

Console.WriteLi ne(ddata[0,0]);
Console.WriteLi ne(ddata[0,1]);
Console.WriteLi ne(ddata[1,0]);
Console.WriteLi ne(ddata[1,1]);

HTH
Kalpesh
Dec 19 '07 #5

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

Similar topics

9
90122
by: FalkoG | last post by:
Hello colleague I want to convert a floating number for example 5236.9856982 to a hexadecimal number. I'd tried several things but my problem is to convert the position after decimal point. I searched numberless websites but nothing could answer my question. I would be pleased to get some help. Regards
3
3464
by: Mansi | last post by:
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;...
5
6353
by: Peter Jansson | last post by:
Hello group, The following code is an attempt to perform URL-decoding of URL-encoded string. Note that std::istringstream is used within the switch, within the loop. Three main issues have been raised about the code; 1. If characters after '%' do not represent hexademical number, then uninitialized value variable 'hexint' used - this is...
0
3642
by: c0dergirl | last post by:
This c# program allows you to select multiple items from a listbox. For each selected item, a worksheet is created in the workbook with some information. Right now I create a chart that plots some information from one of the sheets. What I want to do is have a line on the graph for every sheet. I assume I use multiple datasources to do this,...
0
7605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.