Link to home
Start Free TrialLog in
Avatar of Elena Quinn
Elena Quinn

asked on

How do you copy a list to Excel using VB.net?

Hi Folks,

I'm trying to make a parser from text to Excel.  Some of the text, I know the number of entries there will be and so I can use an array to pull in the data and simply assign the array to the excel range.  No problem.  However, for some data, I don't necessarily know the number of entries and so I am using a list instead of an array.  So how do I quickly get the list into the excel spreadsheet?  I can't seem to find anything.

Here is the example for an array.  Had to make it 2 dimensional (why I don't know), and then set all the empty cells to blank ("").  But then when you set the range = the array, it works fine and is fast.  This is what I need because I don't want to iterate cell by cell.  I'd be waiting for days.

xlWS.Range(xlWS.Cells(row + 1, column), xlWS.Cells(row + 1 + MyInfo(0).Length, column)).Value2 = MyInfo

Open in new window


The below is the list and does not work.

xlWS.Range(xlWS.Cells(row + 1, column), xlWS.Cells(row + strMyList.Count)).Value2 = strMyList

Open in new window


Any insight is most appreciated.
ASKER CERTIFIED SOLUTION
Avatar of aikimark
aikimark
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you have the OpenXML SDK, you might run a speed test to see how long it takes to populate the range a cell-at-a-time.
Avatar of Elena Quinn
Elena Quinn

ASKER

Thanks