How to convert to number in excel?

Hello Community!

Anyone please tell me how can we convert to number in excel?
i have removed the count of each folder’s which contains file,But the problem is the total count is showing 0 because it is showing a error of converting to number in excel.After manually when i convert to number it is working.How can i do this in UiPath?

Hi @Priyesh_Shetty1

Try this
In Range you need to mention the column

I hope it helps!!

Hi @Priyesh_Shetty1

=> Use Read Range workbook activity to read the excel and store in a datatable.
=> Use for each row in datatable activity to iterate the rows in the datatable.
=> Inside for each place an assign activity.
→ - Assign → CurrentRow(“Amount”) = CDbl(CurrentRow(“Amount”).ToString)
=> After the For each activity use the write range workbook to write the datatable to the same excel file.

Check the below workflow for better understanding.

Hope it helps!!

@lrtetala It is telling to convert each and every column to convert to number then only it will get total count.


Try this


@lrtetala I want a dynamic code because daily the column will not be fixed some time there will be 5 columns sometime 3 and sometime 2 like this.


I hope you are writing the data from a datatable to excel …if so you can use the following in invoke code

Dt.AsEnumerable.ToList.ForEach(sub(r) r("Total") = r.ItemArray.Sum(function(x) Cint(x.ToString)).ToString)

Pass the datatablr as in/out argument in the invoke code activity


Excel contains only numbers
If yes

Hope it helps!!

@pravallikapaluri still there is no output

@Anil_G Invoke Code: Exception has been thrown by the target of an invocation…this is the error i got in invoke code.

I have one workflow which is working through macros.
It will convert all your columns to number

@raja.arslankhan yes please show me the ss


Try to check the inner exception details and please tell what it is

you can check from locals panel exception details


@Priyesh_Shetty1 But it will only convert your excel columns format to number

@Anil_G this are the inner exception details…RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.InvalidCastException: Conversion from string “” to type ‘Integer’ is not valid. —> RemoteException wrapping System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value,
NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
— End of inner exception stack trace —
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
at UiPathCodeRunner_7ed5e046b7a64d24abd513679cdcf7ff._Closure$__._Lambda$0-1(Object x)
at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() at System.Linq.Enumerable.Sum(IEnumerable1 source)
at UiPathCodeRunner_7ed5e046b7a64d24abd513679cdcf7ff._Closure$
._Lambda$__0-0(DataRow r)
at System.Collections.Generic.List1.ForEach(Action1 action)
at UiPathCodeRunner_7ed5e046b7a64d24abd513679cdcf7ff.Run(DataTable& dt)
— End of inner exception stack trace —
at System.RuntimeMethodHandle.InvokeMethod(Object target,
Object arguments,
Signature sig,
Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
Object parameters,
Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,
BindingFlags invokeAttr,
Binder binder,
Object parameters,
CultureInfo culture)
at System.RuntimeType.InvokeMember(String name,
BindingFlags bindingFlags,
Binder binder,
Object target,
Object providedArgs,
ParameterModifier modifiers,
CultureInfo culture,
String namedParams)
at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object args)
at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode,
List1 inArgs, IEnumerable1 imps,
Object args)
at UiPath.Core.Activities.InvokeCode.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)


Please use the below…looks like you have some empty values in the list

Dt.AsEnumerable.ToList.ForEach(sub(r) r("Total") = r.ItemArray.Sum(function(x) If(String.IsNullOrEmpty(x.ToString),0,Cint(x.ToString))).ToString)


@raja.arslankhan after converting each column’s to number my total number column get increamented.

@Priyesh_Shetty1 Ok give me excel file I can design macro for you.

@Anil_G again it is throwing exception.

@raja.arslankhan i cant share any file due to company policy…And the columns are not fix sometime there will 2 columns and sometime 6 columns like this it will be.