private void MenuItemExcel_Click(object sender, EventArgs e) { switch (TabControl.SelectedIndex) { case 0: DGVFish.SelectAll(); var data0 = DGVFish.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); }
public void InitDGVStatistics() { using (var context = new BotanicalGardenContext()) { context.Statistics.Load(); DGVStatistics.DataSource = context.Statistics.Local.ToBindingList(); DGVStatistics.Columns["Tree"].Visible = false; DGVStatistics.Columns["Plant"].Visible = false; DGVStatistics.Columns["Id"].HeaderText = "№"; DGVStatistics.Columns["DateTime"].HeaderText = "Дата/Время"; DGVStatistics.Columns["LivingСonditions"].HeaderText = "Среда обитания"; DGVStatistics.Columns["Сondition"].HeaderText = "Состояние"; DGVStatistics.Columns["Population"].HeaderText = "Количество"; DGVStatistics.Columns["TreeId"].HeaderText = "№ дереа"; DGVStatistics.Columns["PlantId"].HeaderText = "№ растения"; DGVStatistics.Refresh(); } }
public void InitDGVStatistics() { using (var context = new AquariumContext()) { context.Statistics.Load(); DGVStatistics.DataSource = context.Statistics.Local.ToBindingList(); DGVStatistics.Columns["Fish"].Visible = false; DGVStatistics.Columns["Plant"].Visible = false; DGVStatistics.Columns["Plant"].Visible = false; DGVStatistics.Columns["Id"].HeaderText = "№"; DGVStatistics.Columns["DateTime"].HeaderText = "Дата/Время"; DGVStatistics.Columns["LivingСonditions"].HeaderText = "Условия обитания"; DGVStatistics.Columns["Nutrition"].HeaderText = "Питание"; DGVStatistics.Columns["Population"].HeaderText = "Популяция"; DGVStatistics.Columns["FishId"].HeaderText = "№ рыбы"; DGVStatistics.Columns["PlantId"].HeaderText = "№ водоросли"; DGVStatistics.Refresh(); } }