C
cendter
Hi there,
I am utterly confused - I have a form that starts an instance from
excel and let's the user select a range. I then want to take this
range as an array of doubles. I ran into trouble because the 1-based
indexing that Excel passes (I think) so after many tries I got:
Excel.Range aRange =
xlApp.get_Range(textBox2.Text.Split(':')[0],textBox2.Text.Split(':')
[1]);
object[,] xacc = new object[aRange.Rows.Count,
aRange.Columns.Count];
xacc = (object[,])aRange.Value2;
to work ... now xacc is an object[,] array but it seems to be 1-
based? Does anyone know how this can be corrected to the normal 0-
based c# arrays.
More importantly, any conversion and casting for either the whole
array to, say, double[,] or just for a single element to double or int
fails with an exception 'Invalid cast'.
Can anyone help or provide an example of how to take a range and
convert it into a two dimensional array of doubles?
Thank you very much.
Sunrider
I am utterly confused - I have a form that starts an instance from
excel and let's the user select a range. I then want to take this
range as an array of doubles. I ran into trouble because the 1-based
indexing that Excel passes (I think) so after many tries I got:
Excel.Range aRange =
xlApp.get_Range(textBox2.Text.Split(':')[0],textBox2.Text.Split(':')
[1]);
object[,] xacc = new object[aRange.Rows.Count,
aRange.Columns.Count];
xacc = (object[,])aRange.Value2;
to work ... now xacc is an object[,] array but it seems to be 1-
based? Does anyone know how this can be corrected to the normal 0-
based c# arrays.
More importantly, any conversion and casting for either the whole
array to, say, double[,] or just for a single element to double or int
fails with an exception 'Invalid cast'.
Can anyone help or provide an example of how to take a range and
convert it into a two dimensional array of doubles?
Thank you very much.
Sunrider