How to move Regex Matches to an excel file

Hi All,

I used ‘matches’ to get a specific text from a big content and enclosed this into a for loop for fetching multiple text from multiple contents.

Now im trying to save these regular expression output into a datatable so that i can input it to an excel file but facing the below error. This error occurs at ‘Add Data Row’ activity. Kindly help. TIA.

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.ArgumentException: Unable to cast object of type 'd__971[System.Text.RegularExpressions.Match]' to type 'System.IConvertible'.Couldn't store <System.Linq.Enumerable+<CastIterator>d__971[System.Text.RegularExpressions.Match]> in Email Ids Column. Expected type is Int32. ----> System.InvalidCastException: Unable to cast object of type ‘d__97`1[System.Text.RegularExpressions.Match]’ to type ‘System.IConvertible’.
at System.Data.Common.Int32Storage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object value)
— End of inner ExceptionDetail stack trace —
at System.Data.DataColumn.set_Item(Int32 record, Object value)
at System.Data.DataTable.NewRecordFromArray(Object value)
at System.Data.DataRowCollection.Add(Object values)
at UiPath.Core.Activities.AddDataRow.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Buddy can i see where the screenshot of where this error occurs with which activity

Its easy buddy we can sort this out, because it just a datatype conversion issue but would like to know where to be converted

Cheers…

@harishk5 Matches itself is a collection of all matches (IEnumerable<Match>) in the text you pass. You need to iterate through the matches result that you get. And to get the actual value, you should use Match.Value

foreach (var match in matches)
{
    match.Value
}

Thanks a lot. Please check the screenshot below which was taken in debug mode. I get this error at ‘Add Data Row’ activity.

Thank you KannanSuresh. I am using foreach to iterate through the collection and then when i try to save it to a data table via ‘Add Data Row’ activity, i get this error. Please find the screenshot below.

Buddy
Inside add data row, for the property arrayrow dont use emailidlist buddy, instead use item as initial method like item.string

This would work buddy

Cheers

1 Like

Thanks buddy…

I used {item.toString} as the arrayrow and again getting error message as below.

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.ArgumentException: Input string was not in a correct format.Couldn’t store bindu.pustakala@evry.com in Email Ids Column. Expected type is Int32. ----> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
at System.Data.Common.Int32Storage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object value)
— End of inner ExceptionDetail stack trace —
at System.Data.DataColumn.set_Item(Int32 record, Object value)
at System.Data.DataTable.NewRecordFromArray(Object value)
at System.Data.DataRowCollection.Add(Object values)
at UiPath.Core.Activities.AddDataRow.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

@harishk5
Its like column datatype exception buddy is email id column is of type string

We can sort out this buddy you are almost done…

Cheers

1 Like

Yes. I have selected the ‘TypeArgument’ in the ‘Add Data Column’ properties as ‘String’. Am i referring to the right property here?

add%20data%20column%20-%20UiPath

But buddy there it was emailid

"An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.ArgumentException: Input string was not in a correct format.Couldn’t store bindu.pustakala@evry.com in Email Ids Column."

here it is emailaddress

Cheers

1 Like

Buddy, i am also confused. I didnt create column name as ‘Email Ids’ in the data table. When i try to rename the column name from emailaddress to ‘Email Ids’, i get this error below. How do i find this Email Ids column and where can i change its type.

Source: Add Data Column

Message: A column named ‘Email Ids’ already belongs to this DataTable.

Exception Type: System.Data.DuplicateNameException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.Data.DuplicateNameException: A column named ‘Email Ids’ already belongs to this DataTable.
at System.Data.DataColumnCollection.RegisterColumnName(String name, DataColumn column)
at System.Data.DataColumnCollection.BaseAdd(DataColumn column)
at System.Data.DataColumnCollection.AddAt(Int32 index, DataColumn column)
at UiPath.Core.Activities.AddDataColumn`1.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Can you show us the details of the data table DT? Its columns etc.

1 Like

Yup. Got it, i totally forgot to change the column configuration inside the datatable. I changed from Int32 to String and it worked. Thanks Palaniyappan and KannanSuresh.

1 Like

Thats amazing buddy

Kindly close this thread with right comment marked as solution that could help others looking for ideas under your topic

Cheers @harishk5

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.