Cursor.Current = Cursors.WaitCursor; Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); app.Visible = true; Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Add(1); Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1]; ws.Range["a1:o1"].Font.Color = System.Drawing.Color.Red; ws.Columns.Font.Bold = true; app.Columns.ColumnWidth = 20; for (int i = 1; i < dataGridView.Columns.Count + 1; i++) { app.Cells[1, i] = dataGridView.Columns[i - 1].HeaderText; } for (int i = 0; i < dataGridView.Rows.Count; i++) { for (int j = 0; j < dataGridView.Columns.Count; j++) { app.Cells[i + 2, j + 1] = Convert.ToString(dataGridView.Rows[i].Cells[j].Value == "" ? "-" : dataGridView.Rows[i].Cells[j].Value); } } Cursor.Current = Cursors.Default;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)