Delete last two columns data and write rest of it in excel

Hi Team,
I want the BOT to delete last two columns data and write rest of it into a new file and save it as csv.Test.xlsx (10.9 KB)

@som17 You can Read the Excel file using Read Range, then you can use the DefaultView.ToTable property to keep only the columns you need.

Try this :

newDT = DT.DefaultView.ToTable(False,DT.Columns.Cast(Of DataColumn).Select(Function(x)x.ColumnName).Take(DT.Columns.Count-2).toArray)

You can then Write the newDT to CSV using Write CSV activity
Check this and let me know if you get any error or if the output is not the Expected one.

1 Like

Hi @som17,

To delete the column you can use the below activity .

Video explanation .

To save as CSV.

Use saveas activity .



i did the same…but BOT is writing the previous data only and not the data that is left after deleting

@som17 I tested with your excel file now and it worked. :sweat_smile: What is the Output that you got ?

Didn’t the last two columns get removed ?

i actually need to delete from column K to col P…and then the leftover data need to written in a new csv

@som17 But earlier you said only 2 two Columns :sweat_smile:

You can alter the count by yourself and get the needed output.

As you can see I am Subtracting 2, which means I’m taking all columns except last 2, you can put 6, As you need to Delete 6 Columns From the Last to the First i.e K, L, M, N, O, P

1 Like

ohh yess…it will work now…thank u so much :slight_smile:

1 Like

hi ,
when i ran this code …while writing csv it added Column1 in the end after into the csv. :frowning:

@som17 Can you Send a Screenshot of what you have done in the workflow, that shouldn’t be happening generslly

i fixed it,… :slight_smile:

1 Like