Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void ExportToExcel(DataGridView dgv)
- {
- if (dgv_report.Rows.Count > 0)
- {
- Microsoft.Office.Interop.Excel.Application xcelApp = new Microsoft.Office.Interop.Excel.Application();
- xcelApp.Application.Workbooks.Add(Type.Missing);
- for (int i = 1; i < dgv_report.Columns.Count + 1; i++)
- {
- xcelApp.Cells[1, i] = dgv_report.Columns[i - 1].HeaderText;
- }
- for (int i = 0; i < dgv_report.Rows.Count; i++)
- {
- for (int j = 0; j < dgv_report.Columns.Count; j++)
- {
- xcelApp.Cells[i + 2, j + 1] = dgv_report.Rows[i].Cells[j].Value.ToString();
- }
- }
- xcelApp.Columns.AutoFit();
- xcelApp.Visible = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement