public void InitDGVTree() { using (var context = new BotanicalGardenContext()) { context.Trees.Load(); DGVTree.DataSource = context.Trees.Local.ToBindingList(); DGVTree.Columns["Statistics"].Visible = false; DGVTree.Columns["Id"].HeaderText = "№"; DGVTree.Columns["Name"].HeaderText = "Название"; DGVTree.Columns["View"].HeaderText = "Вид"; DGVTree.Columns["Family"].HeaderText = "Семейство"; DGVTree.Columns["Rod"].HeaderText = "Род"; DGVTree.Refresh(); } }
private void MenuItemExcel_Click(object sender, EventArgs e) { switch (TabControl.SelectedIndex) { case 0: DGVTree.SelectAll(); var data0 = DGVTree.GetClipboardContent(); if (data0 != null) { Clipboard.SetDataObject(data0); } break; case 1: DGVPlant.SelectAll(); var data1 = DGVPlant.GetClipboardContent(); if (data1 != null) { Clipboard.SetDataObject(data1); } break; case 2: DGVStatistics.SelectAll(); var data2 = DGVStatistics.GetClipboardContent(); if (data2 != null) { Clipboard.SetDataObject(data2); } break; } Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Microsoft.Office.Interop.Excel.Application { Visible = true }; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true); }