i have a Hundred plus excel files. its contains customer data. here in each file in different formats, we don’t know how headers coming and index of that column. so i need to search column names.
in my scenario if i need to find Customer Name , but in excels it might be Cust Name/CustomerName/Cust. Name like this. so, is there any possibility to search like Fuzzy Selectors Selectors/RegEx. if possible string(Column name) Match at least 80%, its would be TRUE.
i need solution for this.
If you know the possibilitie of th names that you can get then you can use below to get which column name is present and then can use it
{"CustomerName","Cust. Name","CustomerName","Cust Name"}.Intersect((From dc In dt.Columns.Cast(Of DataColumn) Select dc.ColumnName).ToArray())(0)
If ypu dont know one more way is to try regex
(From dc In dt.Columns.Cast(Of DataColumn) Select dc.ColumnName).ToArray().Where(function(x) NotString.IsNullOrEmpty(System.Text.RegulrExpressions.Regex.Match(x,"cust.*name",RegexOptions.IgnoreCase).Value))(0)
Thanks for Quick responding. if we know possibilities of input, it would be easy. but my scenario not possible. but i am trying with your answers…
here, {“CustomerName”,“Cust. Name”,“CustomerName”,“Cust Name”}.Except((From dc In dt.Columns.Cast(Of DataColumn) Select dc.ColumnName).ToArray())(0) its always shows first index, that means CustomerName. so why should use list of possibilities in array. can you explain or modify this syntax?
its working, thank you so much. while working on this i found one issue, Some files column had not in a first row, started 3/4/5th rows, so can i find same way that key word(Column name) in sheet?, if not i can move to next sheet. actually i have more sheets(they hide, robot reading those sheets also) so i need to read one by one sheet. please let me know…
thanks for quick respond.
is it possible to search in entire sheet(data table) like as you mentioned ({“CustomerName”,“Cust. Name”,“CustomerName”,“Cust Name”}.Intersect((From dc In dt.Columns.Cast(Of DataColumn) Select dc.ColumnName).ToArray())(0)) like this? (not row by row, need entire sheet at a time)