Excel Script
Excel Script
{
Thread.Sleep(1);
Rectangle screen = Screen.FromControl(this).Bounds;
this.ClientSize = new System.Drawing.Size(screen.Width, i);
//a = a + 30;
}
base.OnDeactivate(e);
this.Close();
DTGRIDVIEWEXCEL = dataGridView1;
}
// storing Each row and column value to excel sheet
for (int i = 0; i < DTGRIDVIEWEXCEL.Rows.Count; i++)
{
for (int j = 0; j < DTGRIDVIEWEXCEL.Columns.Count; j++)
{
if (tabControl1.SelectedTab == tabPage1)
{
worksheet.Cells[i + 5, j + 1] =
DTGRIDVIEWEXCEL.Rows[i].Cells[j].Value.ToString();
}
}
worksheet.Columns.AutoFit();
worksheet.Cells[1, 1].Borders.LineStyle =
Excel.XlLineStyle.xlContinuous;
SaveFileDialog1.ShowDialog();
try
{
workbook.SaveAs(SaveFileDialog1.FileName, Type.Missing,
Type.Missing, Type.Missing,
Type.Missing,
Type.Missing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
this.Cursor = Cursors.Default;
app.Visible = true;
MessageBox.Show("Excel Export Successful");
}
catch (Exception)
{