我在silverlight 4 应用程序上有一个数据网格,我试图通过在silverlight 中调用Excel 的COM 组件来导出到excel。它不断出错并告诉我不支持该功能。我不能完全弄清楚出了什么问题,并相信我的代码是可靠的,但显然不是。
Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
Dim excel As Object = AutomationFactory.CreateObject("Excel.Application")
excel.visible = True
Dim workbook As Object = excel.workbooks
workbook.add()
Dim sheet As Object = excel.activesheet
Dim cell As Object = Nothing
Dim i As Integer = 1
'populate the excel sheet
For Each item In ActivityTypeCountDataGrid.ItemsSource
cell = sheet.cells(i, 1)
cell.Value = item.Activity_Type
cell.ColumnWidth = 50
cell = sheet.cells(i, 2)
cell.Value = item.Activity_Type_Count
cell.ColumnWidth = 50
i += 1
Next item
End Sub
这是数据网格
这是错误