How to convert to number in excel?

@Priyesh_Shetty1 number of columns does not matter we can convert all columns

@Priyesh_Shetty1

Please tell the exception

or use this

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

cheers

@Anil_G exception for this code…Iam using invoke code before write range activity…RemoteException wrapping System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> RemoteException wrapping System.ArgumentException: Column ‘Total’ does not belong to table .
at System.Data.DataRow.GetDataColumn(String columnName)
at UiPathCodeRunner_a993b066d5e14fee938a9b50fb39f8ac._Closure$__._Lambda$__0-0(DataRow r)
at System.Collections.Generic.List1.ForEach(Action1 action)
at UiPathCodeRunner_a993b066d5e14fee938a9b50fb39f8ac.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)

@Anil_G

@Priyesh_Shetty1

As per exception it says your dt does not have total column…can you check please and change name accordingly

cheers

@Anil_G after using ctrl+space i could not get the DT variable i have created a argument also in invoke code…and there iam getting the variable DT.

@Priyesh_Shetty1

dt is the datatable which contains the data from your excel…are you reading it?

cheers

@Priyesh_Shetty1

I see you initialized it…my question is us the dt variable containing data from your excel or what you want to write to your excel?

if yes…does it contain total columns also? if not add the column

cheers

@Anil_G i have already added Total Column using add data column in DT variable.

@Priyesh_Shetty1

But as per error it is clear that total column is not found…can you check if there are any spaces?

Also just to be sure verify in locals panel if you have data as expected

Cheers

@Anil_G your this code worked Dt.AsEnumerable.ToList.ForEach(sub(r) r(“Total”) = r.ItemArray.Sum(function(x) If(String.IsNullOrEmpty(x.ToString),0,Cint(x.ToString))).ToString)…But no changes in excel total count.

@Priyesh_Shetty1

Did you write the data back to excel after this?

cheers

@Anil_G no it did not write the total count
because to write the total count i have to convert the each and every column to number then only total count column get increamented

@Priyesh_Shetty1

The given formula is to get the total count in code and then write it directly to excel

cheers