Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / VS Tools for Office / April 2006

Tip: Looking for answers? Try searching our database.

C# Inserting array objects into excel range

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chetna - 20 Apr 2006 15:20 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.