Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming, microsoft.public.dotnet.languages.csharp
|
|||
|
|||
![]()
Somewhat I remember I used to be able to do sth like the the following
double[,] values = (double[,])excel_range.Value2 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(cell_value.ToString()). The question is there a more efficient way to do the job? I am using Office XP with PIA. Thanks. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Check out CDbl function. CDbl(Range("A1").Value) converts the value in cell
A1 to double. "My interest" wrote: Somewhat I remember I used to be able to do sth like the the following double[,] values = (double[,])excel_range.Value2 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(cell_value.ToString()). The question is there a more efficient way to do the job? I am using Office XP with PIA. Thanks. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry for not making it clealy. I am developing in C# and the
emphasis is to convert multiple cells in one go. If we know all cells in a range contain numeric values, it will be inefficient and slow in accessing / converting one cell by one cell. |
#4
![]()
Posted to microsoft.public.excel.programming, microsoft.public.dotnet.languages.csharp
|
|||
|
|||
![]()
Just to make it clearer, the emphasis is how to convert multiple cells
in a ranger efficiently (e.g. in one call) |
#5
![]()
Posted to microsoft.public.excel.programming, microsoft.public.dotnet.languages.csharp
|
|||
|
|||
![]()
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.Value2 Does this help? Kalpesh |
#6
![]()
Posted to microsoft.public.excel.programming, microsoft.public.dotnet.languages.csharp
|
|||
|
|||
![]()
On Dec 18, 1:39 am, Kalpesh wrote:
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.Value2 Does this help? Kalpesh No,unfortunately this does not work. In C#, it seems that Value2 returns a Object[,] instead of a jagged array. |
#7
![]()
Posted to microsoft.public.excel.programming, microsoft.public.dotnet.languages.csharp
|
|||
|
|||
![]()
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.WriteLine("ok"); ddata[0,0] = 3.5; Console.WriteLine(ddata[0,0]); Console.WriteLine(ddata[0,1]); Console.WriteLine(ddata[1,0]); Console.WriteLine(ddata[1,1]); HTH Kalpesh |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Convert excel (.xls) to tab delimited (.txt) without double quotat | Excel Discussion (Misc queries) | |||
is there an easy way to convert an word xp file to excel xp? | Excel Discussion (Misc queries) | |||
most efficient large range summing? | Excel Programming | |||
Can anyone help me convert to more efficient code? | Excel Programming | |||
more efficient way to lookup a range? | Excel Discussion (Misc queries) |