private void btnExporterError_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing); Microsoft.Office.Interop.Excel._Worksheet worksheet = null; app.Visible = true; // get the reference of first sheet. By default its name is Sheet1. // store its reference to worksheet worksheet = workbook.Sheets["Feuil1"]; worksheet = workbook.ActiveSheet; // changing the name of active sheet worksheet.Name = "Feuil1"; // storing header part in Excel for (int i = 1; i < dataGridView2.Columns.Count + 1; i++) { worksheet.Cells[1, i] = dataGridView2.Columns[i - 1].HeaderText; } DataTable src1 = GetDataTableFromDGV(dataGridView1); DataTable src2 = GetDataTableFromDGV(dataGridView2); ArrayList columnHeader = new ArrayList(); ArrayList columnHeader2 = new ArrayList(); foreach (DataGridViewColumn column in dataGridView1.Columns) columnHeader.Add(column.HeaderText); foreach (DataGridViewColumn column in dataGridView2.Columns) columnHeader2.Add(column.HeaderText); for (int i = 0; i < src1.Rows.Count; i++) { var row1 = src1.Rows[i].ItemArray; var row2 = src2.Rows[i].ItemArray; foreach (string colname in columnHeader) { var cell1 = dataGridView1.Rows[i].Cells[colname].Value; var cell2 = dataGridView2.Rows[i].Cells[colname].Value; var value = dataGridView2.Rows[i].Cells[colname].Value; worksheet .Rows[i + 2] .Cells[dataGridView2.Columns[colname].Index+1] = value; if ((cell1 + "").ToString() != (cell2 + "").ToString()) { worksheet.Cells[i + 2, dataGridView2.Columns[colname].Index + 1] .Interior.color = Color.Red; } } } app.Quit(); }
worksheet.Cells[i + 2, dataGridView2.Columns[colname].Index + 1] .Interior.color = Color.Red;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)