i am facing an issue with some of scraped datatables where the data is not in structed format of a column
as seen below the status of SE ID is randomly disbursed and i am not getting how to capture Terminated or Activated values of the SE ID
is it possible to get the values of that particular row… i am feeling to read each cell in the specific row and if it is Null i need to ignore if not i need to capture the value is there any optimal way for this issue? than what i think
If so then please give this solution a try and let me know if it works out for you.
(From row In dt_data.AsEnumerable()
Let status = row.ItemArray.
Skip(2).
FirstOrDefault(Function(f) Not (IsNothing(f) OrElse String.IsNullOrEmpty(f.ToString)))
Let ra = row.ItemArray.Take(2).Append(status).ToArray()
Select dt_res.Rows.Add(ra)).CopyToDataTable()
hi @ashwin.ashok - if you dont mind can you pls explain what is the logic of the syntaxes, even though i am able to understand the syntaxes of skip and Take i am not able to frame it.
The status is conditionally acquired from each row. We first skip the first two columns since it will always contain values.
The FirstOrDefault fetches the first item that is not null or empty i.e., if it contains text like ‘Terminated’ or ‘Activated’.
The ra variable holds the required data for each row which is then written to the final output.
I’ve also written few articles to get you started on LINQ and you can check them out if you are interested.
i am actually doing a table scrapping from desktop application and when i am doing scraping i am seeing table with different different formats, with some empty columns added in beginging or in middle, not able to understand the logic at backend.
i have attached sample output of scraping could you pls check once and let me know if we add a code for it… DTTypes.xlsx (9.1 KB)
Asssuming that you are expecting three columns in the output, modify the logic and give this a try:
(From row In dt_data.AsEnumerable()
Let ra = row.ItemArray.Where(Function(w) Not(IsNothing(w) OrElse String.IsNullOrEmpty(w.ToString))).ToArray()
Select dt_res.Rows.Add(ra)).CopyToDataTable()
This works if there are only three items with values in a given row i.e., if there are 6 columns with 3 empty cells and 3 cells populated with data, this logic works.