How could we swap columns in excel file, using Invoke Method?


I was trying to swap my columns in a generated Excel file in the same workflow and I was trying to use invoke method for it. It’s showing error as “Value cannot be null”.
In image shown,I am trying to swap my second column to first and first to second.
And could we use it swap multiple columns?

I am attaching the screenshot of the same. And the variables used in it.

Welcome to the forum

have you used on following:

FilteredData.Columns(1) e.g. for reposition the second column?
Ensure FilteredData is valid and not null

once the second sol is repositioned to first postion, the original first col will be already on second position.

not with the SetOrdinal Method.
Give a try on this (Assumption Datatable defines 4 cols):
DtReordered = yourDataTableVar.DefaultView.ToTable(False,{“Col2”,“Col4”,“Col3”,“Col1”})

Thanks @ppr :blush:
I used FilteredData.Columns(“Value Date”) therein, as I wish to move one of my section Value Date to the first position. Should I use Index number there?
Yes, I am getting an output for filtered data

Okay sure, I would be trying on same and would let you know if it works.

Working with Column Name is fine

  • set a breakpoint before the invoke method
  • debug it
  • use the immediate panel and type in following:
 FilteredData.Columns("Value Date")

so you can check if the column is not null by using the statement within invoke method

Hi @ppr
Correct me if I am wrong, Did you meant this(attached image)to use in place of SetOrdinal method? Getting an error
The coulmn names i put in here are as I wish them to be swapped

it was meant as an alternate:

It’s still showing error as such :point_down:

you are missmatching and do part merging two different things. Please rearead the posts from above:

use invoke method, SetOrdinal
use assign and the DefaultView approach

Sorry I get it now, just got confused
Would be checking on same and would update on if it works
Thanks @ppr :v:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.