Identifying multiple column names that do not exist in an excel file

Good Day.

I am trying to validate the columns in an excel. However, I cannot print out the missing column. How can I print the missing column? Kindly refer to the picture below for further details.

Thank you.

Best regards,
Robert

Hi @Robert_Russell_Monsalud

Use for each and change the type to datacolumn

For each item in dt.column

Print item with the if spedified if condition.

If (item.contains("#") and …

Then print item.tostring

Regards

1 Like

Can you elaborate?

@Robert_Russell_Monsalud

Steps would be as follows below.

Read range the excel and create a out dt variable.

Use for each and change type as object to datacolumn

. For each. Item. In ReadDt.columns in for each activity

Item holding all the column present in the worksheet!

Use If condition as you specified !

Like item.contains() and item.contains()…

Condition satisfies then part write line item.tostring

Else leave blank.

Hope this helps!

Regards

1 Like

You’d have to loop through your expected column names, and then check if that column name exists in Columns, and if it doesn’t Log Message to print it ou.

1 Like

According to @Yoichi, it is one of the solutions

First, create string array named names which has column names which is checked.
Then condition of IF is names.All(Function(s) dt.Columns.Contains(s))

And in Else, we can get missing column name from String.Join(",",names.Where(Function(s) not dt.Columns.Contains(s)))

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.