Help in Reading CSV by using Excel Application Scope activity

Hi Team

I have a query related to reading csv file -
I am getting an error while reading csv file -getting error on read csv line 2 contains more values than the header line.
In this case - i have used excel application scope and then read range of excel activity to read csv file. I am able to read it successfully to a data table using this method.
Question : Will there be any trouble that can arise if i use like this.

Thanks.

@syed.khaja

Using the “Excel Application Scope” and “Read Range” activities to read a CSV file may not be the best approach. These activities are typically used to work with Excel files (.xlsx ), but CSV files are plain text files and can be read directly without involving the Excel Application Scope. Instead, you should use the “Read CSV” activity (or its equivalent, depending on the automation tool you’re using) to read CSV files specifically.

Are you getting data in correct format?

Hi, Thanks for the response

The csv file format example is as below
Vr1 vr2
Name RollNo Age
Aaa 123 24

The actual data starts from row no. 2, if I am reading it using Read Csv activity then I am getting an error as - read csv line 2 contains more values than the header line.

The error you’re encountering is likely due to the fact that the Read CSV activity in UiPath is trying to read your CSV file from the first row, which in your case, does not contain the actual headers for your data.

Since your actual data starts from row number 2, one way to handle this would be to use the Read Range activity in combination with the Excel Application Scope activity as you already did. This method allows you to specify the range from where to start reading.

However, please be aware that using the Excel Application Scope activity to read a CSV file can sometimes lead to unexpected results, especially when your CSV file contains data that is not correctly formatted for Excel. For example, if a field in your CSV data contains a comma, Excel might interpret it as a field separator and split the data into multiple cells.

@syed.khaja
Yeah got it. Because in your case line one contains 2 columns and remaining are empty.
According to first row their is only 2 columns and when it tries to fill data it finds more than 2 columns data which is logically wrong in CSV case.

In read range it reads all the data and it sets column according to data that’s why it read successfully.

@syed.khaja

It is not an issue to use use excel file activity…this also supports csv…and for the purpose where the initial rows are formatted differently for a csv we use this and it is ok to use…

Another method would be to use read text file and then ignore the rows you dont need and use generate datatable activity to get the data…

Both the methods would work

Cheers

Thank you all for your inputs.

@Anil_G , thank you for your clarification, if possible can you please share the source of your screenshot.

Thanks

@syed.khaja

Here it is

https://docs.uipath.com/activities/docs/excel-application-card

cheers