I tried using “Remove a Data Column” multiple times but something tells me that there is a more elegant way of getting this done. Also, it keeps giving me errors. I saw another solution that used arrays but I am not sure about the syntax.
Either way you do it (ie .ToTable(), using Remove Data Column activity, or ExcelInsertDeleteColumns), you will need to know which columns you need to delete. This will probably require declaring them globally (from a config or Array variable).
Let’s assume you use an Array variable, then it might simply look like this (not much .net coding needed):
Declare variable: columnsToRemove = {"Col1", "Col2", "Col3"}
For Each col In columnsToRemove // TypeArgument as String
If dt1.Columns.Contains(col)
Remove Data Column using col as ColumnName
or to delete all but specified columns, it would be like this:
Declare variable: columnsToKeep = {"Col1", "Col2", "Col3"}
For Each col In dt1.Clone.Columns // TypeArgument as DataColumn
If Not columnsToKeep.Contains(col.ColumnName)
Remove Data Column using col.ColumnName as ColumnName
So, I believe those are the methods I have used in the past.
If you use .ToTable(), then you can use same array like this: