cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to paste collection into a csv file?

Venkata_Pranav_
Level 6
What is the best way to paste collection into a csv file? Should I use the Word VBO?
Pranav
11 REPLIES 11

MatthewRoss
Level 4
I have now resolved this with adding in a selection of References and Namespace Imports.  

John__Carter
Staff
Staff
FYI I've previously found this kind technique (collection -> object array -> range) to be very effective for writing large collections into Excel. Dim xl, wb, ws As Object wb = Microsoft.VisualBasic.GetObject(ExcelFilePathInput) xl = wb.parent ws = wb.WorkSheets("Sheet1") Dim arr As Object(,) = New Object(CollectionInput.Rows.Count - 1, CollectionInput.Columns.Count - 1) {} For r As Integer = 0 To CollectionInput.Rows.Count - 1     Dim dr As DataRow = CollectionInput.Rows(r)     For c As Integer = 0 To CollectionInput.Columns.Count - 1         arr(r, c) = dr(c)     Next Next Dim c1 As Object = ws.Cells(2, 1) Dim c2 As Object = ws.Cells(CollectionInput.Rows.Count + 1, CollectionInput.Columns.Count) Dim rg As Object = ws.Range(c1, c2) rg.Value = arr