How to remove the empty columns. If the column data is empty under a header how to remove the entire column
refer the below thread.
Test with this expression in an Assign activity:
filteredDT = origDT.DefaultView.ToTable(False, origDT.Columns.Cast(Of DataColumn)().Where(Function(col1) origDT.AsEnumerable().Any(Function(row) Not String.IsNullOrEmpty(row(col1).ToString()))).Select(Function(col2) col2.ColumnName).ToArray)
origDT is your original data table and filteredDT is the new data table with only columns that have any value.
getting the duplicate column names but columns are not removing
getting the duplicate column names but columns are not removing.
Hey @anjani_priya
Can you share the input and expected output file or dummy file.
Regards,
Ajay Mishra
samplefile.xlsx (9.6 KB)
the empty columns index are dynamic
Use below mentioned LinQ in Assign:
dt_Input = dt_Input.DefaultView.ToTable(False, dt_Input.Columns.Cast(Of DataColumn).Select(Function(x) x.ToString).Where(Function(column) dt_Input.AsEnumerable().Any(Function(row) Not String.IsNullOrEmpty(row(column).ToString.Trim))).ToArray)
Workflow Screenshot:
Attaching .xaml for your reference:
UpdateColumnValuesSequence.xaml (8.0 KB)
Hope above LinQ will resolve your issue!
Regards,
Ajay Mishra
If the excel file is different then?
samplefile.xlsx (9.7 KB)
small change
if the header is empty, whether it has values also, the column should remove
@anjani_priya It will work with any excel!
Regards,
Ajay Miishra
no but i need a change in this code, if the column header is empty even if the data is present in the empty header column it should remove the entire column. Once see the above attached excel.
Okay @anjani_priya
then use below mentioned LinQ in Assign Activity:
dt_Input = dt_Input.DefaultView.ToTable(False, dt_Input.Columns.Cast(Of DataColumn).Select(Function(x) x.ToString).Where(Function(column) dt_Input.AsEnumerable().Any(Function(row) Not String.IsNullOrEmpty(row(column).ToString.Trim)) Andalso Not column.ToString.ToLower.Contains("column")).ToArray)
Assign:
Input Output screenshot for your reference:
Regards,
Ajay Mishra
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.