Silverlight 将DataGrid的数据导入到Excel中

1. 要求: OOB, 而且要提升信任.

            dynamic excel = AutomationFactory.CreateObject("Excel.Application");
            excel.Visible = true;
            excel.workbooks.Add();
            dynamic sheet = excel.ActiveSheet;
            dynamic cell = null;
            int i = 1;
            foreach (AGC工程 c in dataGrid1.ItemsSource)
            {
                cell = sheet.Cells[i /*row*/, 1 /*col*/];
                cell.Value = c.gcmc工程名称;
                cell.ColumnWidth = 40;
                cell = sheet.Cells[i /*row*/, 2 /*col*/];
                cell.Value = c.tjsj添加时间;
                cell.ColumnWidth = 30;
                i++;
            }

posted @ 2012-06-16 18:31  Ken-Cai  阅读(179)  评论(0)    收藏  举报