Hallo!
I hope someone can help me with this. Im working with Visual Studio .NET
2003 (C#) and Microsoft Excel 2002.
There are 2 arraylists, one "AL1" with string values and the other "AL2"
with long values. Both have the same length, iLength. I need to insert these
values in 2 Excel columns "A" and "B" respectively. I have converted these
arraylists into arrays using:
string[] strarAL1 = (string[]) AL1.ToArray(typeof(string));
object[] lngarAl2 = (object[]) AL2.ToArray(typeof(long));
With the following I defined a range for the array strarAL1 and lngarAl2
Excel.Application oExAppl = new Excel.Application();
Excel._Workbook oXLWB;
Excel._Worksheet oXLWS;
Excel.Range oXLR;
//oXLR is a range in the activeworksheet oXLWS in the workbook oXLWB of the
application oExApp
oXLR = oXLWS.get_Range("A1", Missing.Value);
oXLR = oXLR.get_Resize(iLength, 1);
oXLR.Value2 = strarAL1;
oXLR = oXLWS.get_Range("B1", Missing.Value);
oXLR = oXLR.get_Resize(iLength, 1);
oXLR.Value2 = lngarAl2;
1. When I insert an object array into a defined range (I tried to see if
that works and it does!!), the array values are displayed correctly. But with
the array converted from the arraylist (as in my case), only the first
arraylist value is inserted (for the entire range of iLength values). Where
is the mistake?
I can of course insert each value individually, but with 30.000 values- HA!
2. For the array with the long values,
long[] lngarB = (long[]) Al1.ToArray(typeof(long));
does not work.(All the values in the arraylist B are stored as "long".) Any
idea why? Casting it with type object works fine though. Just curious.
3. Can I insert an arraylist into the excel range?
oXLR.Value2 = AL1;
doesnt compile.
Id appreciate any help! Thanks in advance
Chetna
Alvin Bruney - 24 Apr 2006 15:32 GMT
You can find more success with the CopyTo function. I think you can assign
the output directly to a range as well.

Signature
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------
> Hallo!
>
[quoted text clipped - 53 lines]
> Id appreciate any help! Thanks in advance
> Chetna