How to remove multiple columns from an excel datatable?

datatable
excel
robot
studio

#1

Hi,

I want to remove multiple columns for an existing datatable from an excel. Is there any way to do this??

Thanks in advance.


#2

Hi @sans.12,

You can use Remove Data Column activity to delete the datatable column by its index number or by its column name.

Regards,
Ranjith.


#3

Thank you for the solution @ranjith. It worked.


#4

Hi @ranjith,

Can I put multiple columns into the ColumnIndex field as I have too many columns to remove ?

Many thanks
Snowman


#5

Instead of that i would prefer to use Dataview.

For more information look into this thread:

Regards…!!
Aksh


Remove multiple columns in EXCEL SHEET
#6

@Snowman, You can’t give multiple column Index/Name in Remove Data Column activity.
Whereas we have an alternate with the combination of LINQ->Datatable

  1. Assign -> String Array arrayOfColumnsToBeRemoved = {“Column1”,“Column2”}

  2. Assign -> Select a Array of ColumnNames without these columns from the datatable dt with the query
    string Array arrayOfColumnsToBeSelected = (From col in dt.Columns.Cast(of System.Data.DataColumn) where not(arrayOfColumnsToBeRemoved.Contains(col.ColumnName)) Select CStr(col.ColumnName)).ToArray()

  3. Assign -> Datatable dt = dt.DefaultView.ToTable(false,arrayOfColumnsToBeSelected)

Regards,
Dom :slight_smile:


Remove multiple columns in EXCEL SHEET
Deleting Colunms form Excel
#7

Dear @aksh1yadav, @Dominic,

Very glad to have the advice promptly !! Thank you very much :grinning: