I need to delete every emtpy column in my datatable. The columns do not have any headers. I saw other forum solutions on this topic, but none of them helped me really out. The empty columns aren’t alwasy at the same spot. The RPA bot should delete every empty column in the range: A:AJ. Furthermore I found out that the write range activity doesnt work on that as well (after filtering). It destroys the formats.
Any ideas on that?
Assign
To: emptyColumns
Value: (From col In Enumerable.Range(0, dt.Columns.Count)
Where dt.AsEnumerable.All(Function(row) row.IsNull(col) OrElse String.IsNullOrEmpty(row(col).ToString()))
Select col).ToList()
For Each
Item: colIndex
Argument Type: Int32
Values: emptyColumns.OrderByDescending(Function(x) x)
Body:
Assign
To: dt.Columns.RemoveAt(colIndex)
Write Range
Range: "A1"
DataTable: dt
AddHeaders: False
get the datatable by reading the excel. Afterwards, you can delete the empty lines with the filter activity and write them back to excel. you can use rowno instead of rowname to avoid headers issue.
sol2:
Use this query
YourDt=YourDt.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(“”))).CopyToDataTable()
As you probably all know, the +1 addition on the ColumnIndex is because the read range activity starts with Index 0, while the Delete column activity doesn’t