title: Export Silverlight Datagrid to Excel using COM object
body: <p>I have a datagrid on a silverlight 4 application that I am trying to export to excel by calling the COM component for Excel in silverlight. It keeps error-ing out and tells me that the functionality is not supported. I can't quite figure out what is wrong and believe my code is solid, obviously not though.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Here is the data grid
  <img src="https://i.stack.imgur.com/Ynb7B.jpg" alt="DataGrid"></p>
  
  <p>Here is the error
  <img src="https://i.stack.imgur.com/LF8Ph.jpg" alt="Error"></p>