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
Anil_G
(Anil Gorthi)
August 27, 2023, 10:55am
3
@Sami_Rajput
Few corrections in the approach provided
Dt.Columns("URL").SetOrdinal(0)
is the correct syntax for vb…not the square brackets
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
Anil_G
(Anil Gorthi)
August 27, 2023, 11:17am
5
@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”
Anil_G
(Anil Gorthi)
August 27, 2023, 6:58pm
8
@Sami_Rajput
At that time may be the the datatable is empty can you check
cheers
Vikas_M
(Vikas M)
August 28, 2023, 1:47am
9
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