将Domino视图数据输出为DataTable时间:2022-12-10 20:04:19 Author:水如烟 大概思路如下,现在的方法将值或值数组全部输出为String,比较粗陋。 Public Function GetViewTable(ByVal view As NotesView) As DataTable If view Is Nothing OrElse Not view.comIsValid Then Return New DataTable Dim table As New DataTable(view.Name) Dim index As Integer = 1 For Each column As String In view.ColumnNames If column Is Nothing Then column = "Col" & index.ToString index += 1 End If If table.Columns.Contains(column) Then column &= "1" End If table.Columns.Add(column) Next view.AllEntries.ForEachViewEntry(AddressOf (New GetViewRow(table)).AppendRow) table.AcceptChanges() Return table End Function Private Class GetViewRow Private table As DataTable Sub New(ByVal table As DataTable) Me.table = table End Sub Public Sub AppendRow(ByVal viewEntry As NotesViewEntry) Dim row As DataRow = table.NewRow For index As Integer = 0 To row.Table.Columns.Count - 1 row(index) = Me.ChangeToString(viewEntry.ColumnValues(index)) Next table.Rows.Add(row) End Sub Private Function ChangeToString(ByVal obj As Object) As String Dim list As New List(Of String) If obj Is Nothing Then GoTo Finish If obj.GetType.IsArray Then For Each current As Object In CType(obj, Array) list.Add(ChangeToString(current)) Next Else list.Add(Me.GetString(obj)) End IfFinish: Return String.Join(";", list.ToArray) End Function Private Function GetString(ByVal singleObj As Object) As String If singleObj Is Nothing Then Return String.Empty Return LzmTW.uSystem.Converter.ChangeTo(Of String)(singleObj) End Function End Class