2011-01-06 62 views
0

有誰知道如何將結構的VB.Net列表複製到Excel範圍內?使用數組並不困難,但我無法獲得可用的結構列表。將結構列表複製到Excel範圍

實施例:

Structure MyStruct 
    Dim MyField1 as String 
    Dim MyField2 as Integer 
End Structure 

Dim MyList As New List(Of MyStruct) 
...populate list of structures... 

Dim rng as Excel.Range = MySheet.Range("A1","B9") 
rng.??? = MyList '*** This is where I get stuck. *** 

回答

0
隨着

自定義結構,迭代是唯一的方法。你不能指望excel足夠聰明,將具有多個字段的結構列表映射到行和列中。

Dim oneMyStruct, i as Long 
i = 1 
For each oneMyStruct in MyList 
    rng.cells(i, 1) = oneMyStruct.MyField1 
    rng.cells(i, 2) = oneMyStruct.MyField2 
    i = i + 1 
next oneMyStruct 
+0

謝謝,阿蘭。這就是我所想的,但僅僅是它可能完成的機會......;) – KDP 2011-01-06 18:40:36

相關問題