Skip to main content

Some Common LinQ used in Excel Automation



  • LinQ used on DataTable to Filter One Column and Copy the Data into DataTable: dataTable.Select.where(Function(x) (x.Item("Column1").ToString.ToLower.Contains("Value"))).copyToDatatable.
  • LinQ used on DataTable to Filter More than one Column and Copy the Data into DataTable:
dataTable.Select.where(Function(x)(x.Item("Column1").ToString.ToLower.Contains("Value1") Or x.Item("Column2").ToString.ToLower.Contains("Value2"))).copyToDatatable.
  • LinQ used on DataTable to one Column and Copy the Data into List of DataRows:
dataTable.Select.Where(Function(x) (x.Item("Column1").ToString.ToLower.Contains("Value"))).ToList()
  • LinQ used on DataTable to one Column and Copy the Data into List/DataTable:
dataTable.Select("[Column]='Value'")
  • LinQ used on DataTable to one Column and check whether value present in that Column or not:
dataTable.AsEnumerable().Any(Function(x) x("Column").ToString.Equals("Value"))

It provides you Boolean Value as a result.
  • LinQ used on List to check Outlook inbox Subject and Copy the data into List:
varinboxMails.where(Function(x) x.Subject.toString.Contains(“Value”)).toList()
  • LinQ used on DataTable to one Column with LIKE operator and Copy the Data into List/DataTable:
dataTable.Select("Convert([Column],'System.String') like'%Value%'")).toList()
  • LinQ used on DataTable to one Column and Copy the Data into List of Objects:
(From x In dataTable Select x("Column")).toList()
  • LinQ used on DataTable to one Column to find Distinct Values and Copy the Data into List of Objects:
(From x In dataTable Select x("Column")).Distinct().toList() 


Happy Automation!!

Comments