Get only specific columns from Excel worksheet to Collection using Code stage
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-04-20 05:18 PM
Hi All,
I need to extend the MS Excel VBO action "Get worksheet as collection"to get only specific columns , which can be specified either as comma separated string or collection. Can you please assist me with the code stage for the same?
Regards
------------------------------
Sufiya S
------------------------------
I need to extend the MS Excel VBO action "Get worksheet as collection"to get only specific columns , which can be specified either as comma separated string or collection. Can you please assist me with the code stage for the same?
Regards
------------------------------
Sufiya S
------------------------------
8 REPLIES 8
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
15-04-20 05:28 PM
Hi Sufiya,
You can try reading the entire worksheet to a collection with the MS Excel VBO and then split the collection as an alternative. This mechanism already exists in the 'Split Collection' action of the 'Utility - Collection Manipulation' VBO and works quite well in these cases. This may save you some code writing!
Cheers!
------------------------------
Jorge Barajas
Blue Prism
Senior Product Consultant
Austin, Texas
------------------------------
You can try reading the entire worksheet to a collection with the MS Excel VBO and then split the collection as an alternative. This mechanism already exists in the 'Split Collection' action of the 'Utility - Collection Manipulation' VBO and works quite well in these cases. This may save you some code writing!
Cheers!
------------------------------
Jorge Barajas
Blue Prism
Senior Product Consultant
Austin, Texas
------------------------------
Jorge Barajas
Blue Prism
Senior Product Consultant
Austin, Texas
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
21-04-20 09:47 PM
In case it's still useful, here's some code I created a while back for this particular issue. After reading data from Excel, you can call this code to select only specific columns.
Inputs:
Collection In (Collection)
Column Names (Collection)
Outputs:
Collection Out (Collection)
Whatever column names are specified in the Column Names collection will be selected.
------------------------------
Nicholas Zejdlik
RPA Developer
------------------------------
Inputs:
Collection In (Collection)
Column Names (Collection)
Outputs:
Collection Out (Collection)
For Each Row As DataRow In Column_Names.Rows If Not Collection_In.Columns.Contains(Row(0)) Then Throw New Exception("Field '" & Row(0) & "' does not exist in the collection.") Else Collection_Out.Columns.Add(Collection_In.Columns(Row(0)).ColumnName, Collection_In.Columns(Row(0)).DataType) End If Next For Each Row As DataRow In Collection_In.Rows Dim NewRow As DataRow = Collection_Out.NewRow For Each Column As DataColumn In Collection_Out.Columns NewRow(Column.ColumnName) = Row(Column.ColumnName) Next Collection_Out.Rows.Add(NewRow) Next
Whatever column names are specified in the Column Names collection will be selected.
------------------------------
Nicholas Zejdlik
RPA Developer
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
22-04-20 07:10 AM
Hi Nicholas,
Thanks a lot for your help!!
I am currently facing some issue with the instance handle though so will fix that and try this out , just wanted to confirm how are the Column names are being specified in the Column Names Collection . It is a single column in Column Names Collection and cell values specify the required columns right?
A screenshot for how Column Names Collection looks would help .
Regards
------------------------------
SHaikh
------------------------------
Thanks a lot for your help!!
I am currently facing some issue with the instance handle though so will fix that and try this out , just wanted to confirm how are the Column names are being specified in the Column Names Collection . It is a single column in Column Names Collection and cell values specify the required columns right?
A screenshot for how Column Names Collection looks would help .
Regards
------------------------------
SHaikh
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
22-04-20 02:00 PM
> It is a single column in Column Names Collection and cell values specify the required columns right?
You got it! Since the code uses For Each over the Column Names collection, and refers to the values using Row(0), it'll grab whichever column names are in the first column of the collection, and each row would correspond to a different column name:

You got it! Since the code uses For Each over the Column Names collection, and refers to the values using Row(0), it'll grab whichever column names are in the first column of the collection, and each row would correspond to a different column name:
------------------------------
Nicholas Zejdlik
RPA Developer
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
24-04-20 06:52 AM
Thank you Nicholas for your help !!!! 🙂
------------------------------
SHaikh
------------------------------
------------------------------
SHaikh
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-03-21 12:24 PM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
29-01-22 05:20 PM
Hi Nicolas,
Kindly can you help me in how to select the columns B,C,D,E,F after filtering AC column with @ symbol.
------------------------------
Marina Dutta
------------------------------
Kindly can you help me in how to select the columns B,C,D,E,F after filtering AC column with @ symbol.
------------------------------
Marina Dutta
------------------------------
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
31-01-22 09:01 AM
Hi Marina,
There seem to be two things going on:
#BPTechTips
As searching this community for me rarely provides what I am looking for, I can recommend searching for whatever you are looking for via your favorite search engine (google in my case), as this is more likely to point to answers related to your question. Just a thought...
------------------------------
Happy coding!
Paul
Sweden
------------------------------
There seem to be two things going on:
- Filtering a collection for a given value:
This can be easily done by using BP out of the box actions - Selecting only a few columns:
For the selection of only a few columns I refer to previous threads in this community that handle exactly that and even provide an excellent solution in the form of a Code stage. Obviously, this can also be done by using native BP actions.
#BPTechTips
As searching this community for me rarely provides what I am looking for, I can recommend searching for whatever you are looking for via your favorite search engine (google in my case), as this is more likely to point to answers related to your question. Just a thought...
------------------------------
Happy coding!
Paul
Sweden
------------------------------
Happy coding!
Paul, Sweden
(By all means, do not mark this as the best answer!)
Paul, Sweden
(By all means, do not mark this as the best answer!)
