DataGridView[] Data = DataGridView[0]; DataGridView[] Temp = new DataGridView[Data.Length + 1]; System.Array.Copy(Data, 0, Temp, 0, Data.Length); Temp[Data.Length] = dgHIIT; MessageBox.Show("Item Added to Program", "Item Added", MessageBoxButtons.OK, MessageBoxIcon.Information); Data = Temp; Export Click Microsoft.Office.Interop.Excel.Application wapp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Worksheet wsheet; Microsoft.Office.Interop.Excel.Workbook wbook; wapp = new Microsoft.Office.Interop.Excel.Application(); wapp.Visible = false; wbook = wapp.Workbooks.Add(true); wsheet = (Microsoft.Office.Interop.Excel.Worksheet)wbook.ActiveSheet; foreach(DataGridView item in Data) { try { for (int i = 0; i < item.Columns.Count; i++) { wsheet.Cells[1, i + 1] = item.Columns[i].HeaderText; } for (int i = 0; i < item.Rows.Count; i++) { DataGridViewRow row = item.Rows[i]; for (int j = 0; j < row.Cells.Count; j++) { DataGridViewCell cell = row.Cells[j]; try { wsheet.Cells[i+2, j + 1] = (cell.Value == null) ? "" : cell.Value.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } catch (Exception ex1) { MessageBox.Show(ex1.Message); } } wapp.UserControl = true; wapp.Visible = true;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)