Please read my issue before responding. Have a look at the second image attached in more detail.
Problem is not with writing to the excel file. My “Add Headers” selection is ticked in any case.
The problem is with the column names that were incorrectly assigned to some auto generated name “Column-N” as apposed to the to the column heading from the HTML table.
I tried to understand and totally lost at the above line that’s the reason I asked you for the result before sending the code. Sorry if it doesn’t help.
I used the scraping, it then created the ExtractData activity which fail to detect the column names from the first row.
That is why I also asked if someone can point me to the documentation of the ExtractMetadata property…
Apart from what @vvaidya suggested, what you can do is after using data scraping activity on your web page, when you write the data in the excel, do not check the “Add Headers” property to avoid adding "Column* headers in the excel. This is because the header row of your table is being considered as a data row due to the way the HTML table is designed as also initially mentioned above by @vvaidya.
Thanks for the reply.
We do not have control over that system and we cannot request a change for that. That is exactly the point of UiPath - to build bots that work with existing systems…
I believe it should be a feature of the ExtractData activity to define that the first row - regardless of TH or TD should be used as column names. It like reading data from CSV - you can normally define that the 1st row of data is actually the column names…
It’s still doable, just not as straightforward as with automatic extraction.
Let’s break it down:
Webpage is structured that the header row is not distinguishable from data rows.
You want the datatable columns to be named correctly (obviously). By correctly is meant that the automatic column names should be overwritten with data from the first row.
What you can do:
Read the data as you did before.
Overwrite the column names using a loop (I’ll use foreach in this example): foreach (int index in Enumerable.Range(0, mydt.Columns.Count) { mydt.Columns(index).ColumnName = mydt.Rows(0)(index).ToString) } RemoveDataRow(DataTable = mydt, RowIndex = 0)
What this does is it overwrites column names with string values from first row, then removes it.
RemoveDataRow is an activity.
This should fill your needs. Automatic extraction is very good (IMHO), but it depends on how the source is structured. Sometimes if the input is less than ideal, you need to improvise.
Also might be just my paranoia, but I’m always hesitant to read-write-read data (especially with anything relating to excel), as there’s always a possibility that something (like formatting) might get altered in the middle. In memory alterations are IMHO safer in that regard, since they don’t involve additional software that may throw a fit in some edge cases.
Overwrite the column names using a loop (I’ll use foreach in this example):
foreach (int index in Enumerable.Range(0, mydt.Columns.Count)
{
mydt.Columns(index).ColumnName = mydt.Rows(0)(index).ToString)
}
RemoveDataRow(DataTable = mydt, RowIndex = 0)
Please will you explain where each element of the loop statement needs to be written in the, for each, activity.