The below code when exporting to excel gives the sheet name Book1. How can i edit it to where export the sheet name as "Sams Report"?
- private void btn_Export_Click(object sender, EventArgs e)
- {
- if (dataGridView1.Rows.Count > 0)
- {
- Microsoft.Office.Interop.Excel.ApplicationClass XcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
- XcelApp.Application.Workbooks.Add(Type.Missing);
- // Storing header part in Excel
- for (int i = 1; i < dataGridView1.Columns.Count + 1; i++)
- {
- XcelApp.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText;
- }
- // Storing Each row and column value to excel sheet
- for (int i = 0; i < dataGridView1.Rows.Count; i++)
- {
- for (int j = 0; j < dataGridView1.Columns.Count; j++)
- {
- XcelApp.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();
- }
- }
- XcelApp.Columns.AutoFit();
- XcelApp.Visible = true;
- }
- }
ram kumarPosted Feb 19, 2019, 6:11 AM
Posted Feb 19, 2019, 12:03 AM
SriHari VPPosted Nov 30, 2017, 9:24 PM
Leon DPosted Nov 30, 2017, 8:36 PM
Amit GuptaPosted Nov 30, 2017, 6:13 PM
james jamesPosted Nov 30, 2017, 4:49 PM
Amit GuptaPosted Nov 29, 2017, 9:27 PM
james jamesPosted Nov 29, 2017, 4:39 PM
Amit GuptaPosted Nov 29, 2017, 3:01 PM