| For Each dc In dt.Columns
xl.Range("A1").Offset(0, iCols).Value = dc.ColumnName
iCols += 1
Next
所有剩下的工作就是遍历表的所有行,使用DataRow对象的ItemArray属性来将每个数据行的内容写到工作表的一行中。这大约是Excel将要直接支持DataSet对象最显著的征兆。
''''Add the data
Dim iRows As Int32
For iRows = 0 To dt.Rows.Count - 1
xl.Range("A2").Offset(iRows).Resize(1, iCols).Value = _
dt.Rows(iRows).ItemArray()
Next
Catch ex As Exception
这个过程中其余的代码更新UI,并对工作表应用内建的格式化。
Finally
xl.ScreenUpdating = True
End Try
''''Make the sheet pretty
With xl.ActiveSheet.Range("A1")
.AutoFilter()
.AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormatSimple)
End With
xl = Nothing
End Sub
尽管Microsoft Office System本质上不支持.NET对象,但是DataSet的对象模型和功能使得将其结合到Microsoft Office System中,实现数据交互任务非常简单。
注意: 你可以放心使用这个技术,而不用担心DataSet来自何处,它甚至可以来自于.NET组件或Web服务。
上一页 [1] [2] |