MSDN Support, feel free to contact Jack,įirstHeading SecondHeading ValueinSheet1 ValueinSheet2 so no need to check for valueĪccording to your advice, I have modified my code.
Here Heading Y is on both the sheets but 2nd heading value is different(ff and bb) so it will not go futher to check the value.Īnd Same for P(it have hh value in sheet1 and ll in sheet 2). In this i have to give different data as well as data which is not in sheet1. then how can i add, i mean it should read data of sheet automatically. May be on new excel sheet there is X and xx. You are adding A to sheet 1 then sheet 2. and maybe on this case there is 5 columns. It should read data of sheet automatically not manually. You are putting manually data on the sheet. I am really thankful to you that you helped. Public static DataTable datatable(string path,string sheetName) static void Main(string args)ĭataTable sheet1 = datatable("D:\\test.xlsx", "Sheet1") ĭataTable sheet2 = datatable("D:\\test.xlsx", "Sheet2") MSDN Support, feel free to contact adwikcool,īased on your description, you want to compare 2 excel sheet and save the results(differences) to the another file. If you have any compliments or complaints to This can be beneficial to other community members reading this thread. Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. Using (OleDbDataAdapter da = new OleDbDataAdapter()) Using (OleDbCommand comm = new OleDbCommand())Ĭomm.CommandText = "Select * from " Using (OleDbConnection conn = new OleDbConnection(connectionString)) String connectionString = Source=" + path + " " + "Extended Properties='Excel 12.0 Xml HDR=YES IMEX=1 MAXSCANROWS=0'" Public static DataTable datatable(string path, string sheetName) Select(row => string.Join(",", row.ItemArray)) įile.WriteAllLines("D:\\excel.csv", lines) Var header = string.Join(",", columnNames) List lst2 = (from d in sheet2.AsEnumerable() select d.Field(a)).ToList() List lst1 = (from d in sheet1.AsEnumerable() select d.Field(a)).ToList()
("ValueinSheet2", typeof(int)) įoreach (DataColumn column in sheet1.Columns)įoreach (DataColumn column1 in sheet2.Columns) class ProgramĭataTable sheet1 = datatable("D:\\Test1\\test.xlsx", "Sheet1") ĭataTable sheet2 = datatable("D:\\Test1\\test.xlsx", "Sheet2")
#BEST WAY TO COMPARE TWO COLUMNS IN EXCEL CODE#
I have modified my code according to your advice, you could try the following code.