<https://www.portugal-a-programar.pt/forums/topic/72735-excel-gridview-winforms/>
<http://schema.org/text>
"Olá, \nTenho uma grid q nas 2 primeiras colunas tenho uma checkbox e um botao. \nQuero passar a informação q esta na grid para o excel, excepto a checkbox e o botao. Alias, se ficar da me erro. \n \n\nif (txtexcel.Text != string.Empty)\n\t {\n\t\t if (dataGridView1.Rows.Count &gt; 0)\n\t\t {\n\t\t\t try\n\t\t\t {\n\t\t\t\t //dataGridView1.Columns[0].Visible = false;\n\t\t\t\t //dataGridView1.Columns[1].Visible = false;\n\t\t\t\t // Bind Grid Data to Datatable\n\t\t\t\t DataTable dt = new DataTable();\n\t\t\t\t foreach (DataGridViewColumn col in dataGridView1.Columns)\n\t\t\t\t {\n\t\t\t\t\t dt.Columns.Add(col.HeaderText, col.ValueType);\n\t\t\t\t }\n\t\t\t\t int count = 0;\n\t\t\t\t foreach (DataGridViewRow row in dataGridView1.Rows)\n\t\t\t\t {\n\t\t\t\t\t if (count &lt; dataGridView1.Rows.Count - 1)\n\t\t\t\t\t {\n\t\t\t\t\t\t dt.Rows.Add();\n\t\t\t\t\t\t foreach (DataGridViewCell cell in row.Cells)\n\t\t\t\t\t\t {\n\t\t\t\t\t\t\t dt.Rows[dt.Rows.Count - 1][cell.ColumnIndex] = cell.Value.ToString();\n\t\t\t\t\t\t }\n\t\t\t\t\t }\n\t\t\t\t\t count++;\n\t\t\t\t }\n\t\t\t\t // Bind table data to Stream Writer to export data to respective folder\n\t\t\t\t StreamWriter wr = new StreamWriter(@\"C:/Users/Diogo/Documents/visual studio 2015/Projects/CJProj/CJProj/App_Data/\" + txtexcel.Text + \".xls\");\n\t\t\t\t // Write Columns to excel file\n\t\t\t\t for (int i = 2; i &lt; dt.Columns.Count; i++)\n\t\t\t\t {\n\t\t\t\t\t wr.Write(dt.Columns[i].ToString().ToUpper() + \"\\t\");\n\t\t\t\t }\n\t\t\t\t wr.WriteLine();\n\t\t\t\t //write rows to excel file\n\t\t\t\t for (int i = 0; i &lt; (dt.Rows.Count); i++)\n\t\t\t\t {\n\t\t\t\t\t for (int j = 0; j &lt; dt.Columns.Count; j++)\n\t\t\t\t\t {\n\t\t\t\t\t\t if (dt.Rows[i][j] != null)\n\t\t\t\t\t\t {\n\t\t\t\t\t\t\t wr.Write(Convert.ToString(dt.Rows[i][j]) + \"\\t\");\n\t\t\t\t\t\t }\n\t\t\t\t\t\t else\n\t\t\t\t\t\t {\n\t\t\t\t\t\t\t wr.Write(\"\\t\");\n\t\t\t\t\t\t }\n\t\t\t\t\t }\n\t\t\t\t\t wr.WriteLine();\n\t\t\t\t }\n\t\t\t\t wr.Close();\n\t\t\t\t //dataGridView1.Columns[0].Visible = true;\n\t\t\t\t //dataGridView1.Columns[1].Visible = true;\n\t\t\t\t MessageBox.Show(\"Dados exportados com sucesso\");\n\t\t\t }\n\t\t\t catch (Exception ex)\n\t\t\t {\n\t\t\t\t Log.Save(\"Erro inesperado: \" + ex.Message + \"\", Util, \"\", \"\", 0);\n\t\t\t }\n\t\t }\n\t }\n\t else\n\t { MessageBox.Show(\"Colocar nome no excel\"); }\n\n\n "
<https://www.portugal-a-programar.pt/forums/topic/72735-excel-gridview-winforms/>