如何读取 Excel ListObject 的数据绑定
我有一个 VS 2010 Excel 2007 工作簿应用程序。我有一个通过绑定源绑定到对象数据源的 ListObject。我希望能够确定 ListObject 的 ListColumns 集合中的任何给定 ListColumn 对象绑定到我的对象的什么属性。在下面的示例中,我使用列名称来查找绑定到“Field1”属性的列。但是,在我的情况下,列名称可能与属性名称不同。 ListColumn 对象上没有 DataMember、DataPropertyName 或类似属性,如何确定哪个列绑定到哪个属性?
给定下面的类和 ListObject,我希望能够使用以下代码:
return FindColumn(MyDataListObject, "Property1")
Public Class MyData
Public Property Field1 As String
Public Property Field2 As Date
End Class
Public Function FindColumn(ByVal listObject As ListObject,
ByVal propertyName As String) As ListColumn
For Each col As ListColumn In listObject.ListColumns
If col.Name = propertyName Then
Return col
End If
Next
Return Nothing
End Function
I have a VS 2010 Excel 2007 Workbook application. I have a ListObject that is bound to an object data source via a binding source. I want to be able to determine what property of my object any given ListColumn obect in my ListObject's ListColumns collection is bound to. In the example below I use the column name to find the column that is bound to the "Field1" property. However, in my situation, the column name can be different from the property Name. There is no DataMember, DataPropertyName, or similar property on a ListColumn object, how do I figure out what column is bound to what property?
Given the class and ListObject below, I want to be able to use the following code:
return FindColumn(MyDataListObject, "Property1")
Public Class MyData
Public Property Field1 As String
Public Property Field2 As Date
End Class
Public Function FindColumn(ByVal listObject As ListObject,
ByVal propertyName As String) As ListColumn
For Each col As ListColumn In listObject.ListColumns
If col.Name = propertyName Then
Return col
End If
Next
Return Nothing
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有类似的情况,我需要 Excel 上的数字绑定列。
不幸的是,VSTO 隐藏了存储信息的字段。
访问此信息的唯一方法是通过System.Reflection。
请看下面的小例子:
希望对您有帮助!
特奥巴尔多
I have a similar situation and I need figure bound columns on Excel.
Unfortunally, The VSTO hide the fields where the information is stored.
The only way to access this information by System.Reflection.
See below the small example:
I hope help you !
Teobaldo