public void export_datagridview_to_excel(DataGridView dgv, string excel_file)
{
int cols;
StreamWriter wr = new StreamWriter(excel_file);
cols = dgv.Columns.Count;
for (int i = 0; i < cols; i++)
{
wr.Write(dgv.ColumnsIdea.Name.ToString().ToUpper() + "\t");
}
wr.WriteLine();
for (int i = 0; i < (dgv.Rows.Count - 1); i++)
{
for (int j = 0; j < cols; j++)
{
if (dgv.RowsIdea.Cells[j].Value != null)
wr.Write(dgv.RowsIdea.Cells[j].Value + "\t");
else
{
wr.Write("\t");
}
}
wr.WriteLine();
}
wr.Close();
}