Issue- "Writing Range" activity writing the data in wrong order

I am scraping the data and then writing it inside an Excel sheet, using the Write Range activity, but it is writing in the Excel in the wrong order.

For example the order in Scraping Wizard is

URL | Website | Owner

but sometimes it writes in Excel in the random order like this

Owner | Website | URL

What could be the issue?

Actually I have to merge that sheet with other sheets but if the order is different then there will be the issue…

For example in the owner column I’ll be getting URL’s…

thanks in advance

@Sami_Rajput - You can try to use the SetOrdinal method like so to force the positions of the Columns:

dataTable.Columns["URL"].SetOrdinal(0);
dataTable.Columns["Website"].SetOrdinal(1); 
dataTable.Columns["Owner"].SetOrdinal(2); 

Read more about it: DataColumn.SetOrdinal(Int32) Method (System.Data) | Microsoft Learn

1 Like

@Sami_Rajput

Few corrections in the approach provided

  1. Dt.Columns("URL").SetOrdinal(0) is the correct syntax for vb…not the square brackets
  2. this is to be used in invoke code with dt being passed as in/out argumnet

Cheers

1 Like

@Anil_G @argin.lerit
Will this invoke code, be used right after “Scraping Activity” every time, as I have many scraping wizards for my particular scenario

@Sami_Rajput

Yes please use it after acrapping…

Also make sure the column names are correct

Cheers

@Anil_G @argin.lerit

Sometimes I am getting this Exception

“Exception has been thrown by target of an invocation”

@Sami_Rajput

At that time may be the the datatable is empty can you check

cheers

Hey @Sami_Rajput ,

After scraping Try using the below code in an assign activity and check
YourDT.DefaultView.ToTable(FALSE, "URL","Website","Owner")

Like this:

So, this will always write the columns in the given order only and also note that it will write only 3 columns, other columns get discarded

Hope it helps you out