2012-03-22 104 views
0

我创建Silverlight应用程序,同时将网格导出到Excel中,我需要打开一个新的Excel表格,但我无法在Silverlight中打开一个新的Excel。我使用Telerik控件,在他们的例子中,他们保存了一个新的excel,然后交换数据。但是我的客户端在导出网格数据之前不需要执行保存操作。 流程应该如下图所示: 1.打开新的excel(Excel应该在屏幕前) 2.导出数据 3.保存excel是最终用户的选择。从Silverlight打开新的Excel表格

最终用户可能会或可能不会根据他们的需要保存Excel工作表。

任何人都可以帮助我解决这个问题。

谢谢

+0

你想打开excell工作表,然后填写silverlight的数据? – Rumplin 2012-03-22 08:11:38

回答

1
private void button8_Click(object sender, RoutedEventArgs e) 
    { 
     dynamic excelApp; 
     excelApp = AutomationFactory.CreateObject("Excel.Application"); 
     excelApp.Visible = true; 
     dynamic workbook = excelApp.workbooks; 
     workbook.Add(); 
     dynamic sheet = excelApp.ActiveSheet; 
     dynamic cell = null; 
     int index = 1; 
     foreach (unite emp in dataGrid1.ItemsSource) 
     { 
      cell = sheet.Cells[index, 1]; 
      cell.Value = emp.unite_description; 
      cell = sheet.Cells[index, 2]; 
      //cell.Value = emp.EmployeeId; 
      //cell = sheet.Cells[index, 3]; 
      //cell.Value = emp.Department; 
      index++; 
     } 
    } 

这是我发现的时候我有同样的问题,因为你和它的工作,你问。 (声明变量为动态可能不是必需的)

+0

请告诉我,如果答案对你有用(并且如果是的话) – Oliver 2012-03-23 09:25:37