Add column name in an already existing sheet in Excel

Add column name in an already existing sheet in Excel.

There are 5 columns in a sheet with data, I want to add 4 more column names beside the already existing columns, ( just column names, No data)

1 Like

Hi @ayushi_jain3

You can use Insert Column activity under Excel Process scope.(Modern Experience)

Hope it helps!!
Regards,

@ayushi_jain3

Read range the excel file

Take arrayOfString={“Column Names”}

Take for each loop

Add data column activity: In the column name:Give CurrentItem

Hi @ayushi_jain3

  1. Use the Read Range activity to read the contents of the Excel file.
    Take arrayOfString={“Column Names”}
    Take for each loop
    2.Use the Add Data Column activity to add the Current item to the Excel file.
    3.Use the Write Range activity to write the contents of the Excel file back to the file.

Hope it helps!!

Hi @ayushi_jain3

For workbook activities, use the Add date column activity
image

For excel activities, use the Insert column activity
image

For using Insert column activity you have to encapsulate with in excel process scope and use excel file activities.

Hope it helps!!

Hi @ayushi_jain3

Use Insert Column activity

image

In this you can specify the column name after or before you can add.

or use Add Data Column activity

image

I hope it helps!!

  1. Use the “Excel Application Scope” activity to open the Excel file that contains the sheet where you want to add the column name.
  2. Use the “Read Range” activity
  3. Use the “Add Data Column” activity to add a new column to the DataTable obtained from the “Read Range” activity. Set the “ColumnName” property.
  4. Use a “For Each Row” activity to loop through each row of the DataTable.
  5. Inside the “For Each Row” activity, use the “Assign” activity to set the value of the new column for each row
  6. After the “For Each Row” activity, use the “Write Range” activity to write the updated DataTable back to the Excel sheet.

Hello @ayushi_jain3,
By using Modern Excel activity you can insert the column.
Refer this video, you may get some idea.

If you are a classic user, follow this step to get the modern activity.

  1. In an activity panel click the filter icon
  2. Enable the Modern activity option and you can access the Modern activities.
    image

Hi @lrtetala - Thanks for this. I have a question.

  1. In insert column activity what should we give as range?
  2. In adddatacolumn activity, what should we give in " Column"?

Thanks in advance !

@ayushi_jain3

  1. Excel.Sheet(“Sheet1”).Range(“”)

  2. Dont consider Column
    In Column Name Mention your ColumnName

@ayushi_jain3

Please find below images

image

I hope it helps!!

@ayushi_jain3

If you got the solution for your issue. Please mark it as solution to close the thread.

Regards,

Hii @lrtetala

It’s giving this error while executing:

"22.10.3+Branch.master.Sha.def2351dc828ccfbcddb6e9e07c9cf71b5bf55da

Could not load file or assembly ‘UiPath.Excel.Activities, Version=2.16.0.0, Culture=neutral, PublicKeyToken=null’. The system cannot find the file specified.

System.IO.FileNotFoundException: Could not load file or assembly ‘UiPath.Excel.Activities, Version=2.16.0.0, Culture=neutral, PublicKeyToken=null’. The system cannot find the file specified. at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Reflection.RuntimeMethodInfo.<get_Signature>g__LazyCreateSignature|24_0()
at System.Reflection.RuntimeMethodInfo.<get_InvocationFlags>g__LazyCreateInvocationFlags|13_0()
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at System.Activities.ScriptingJitCompiler.CompileExpression(ExpressionToCompile expressionToCompile)
at System.Activities.JitCompilerHelper1.Compile[T](LocationReferenceEnvironment environment, Boolean isLocationReference) at System.Activities.JitCompilerHelper1.Compile[T](CodeActivityPublicEnvironmentAccessor publicAccessor, Boolean isLocationReference)
at Microsoft.VisualBasic.Activities.VisualBasicHelper.Compile[T](String expressionText, CodeActivityPublicEnvironmentAccessor publicAccessor, Boolean isLocationExpression)
at Microsoft.VisualBasic.Activities.VisualBasicValue1.CacheMetadata(CodeActivityMetadata metadata) at System.Activities.CodeActivity1.OnInternalCacheMetadataExceptResult(Boolean createEmptyBindings)
at System.Activities.Activity1.OnInternalCacheMetadata(Boolean createEmptyBindings) at System.Activities.Activity.InternalCacheMetadata(Boolean createEmptyBindings, IList1& validationErrors)
at System.Activities.ActivityUtilities.ProcessActivity(ChildActivity childActivity, ChildActivity& nextActivity, Stack1& activitiesRemaining, ActivityCallStack parentChain, IList1& validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback)
at System.Activities.ActivityUtilities.ProcessActivityTreeCore(ChildActivity currentActivity, ActivityCallStack parentChain, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList1& validationErrors) at System.Activities.ActivityUtilities.CacheRootMetadata(Activity activity, LocationReferenceEnvironment hostEnvironment, ProcessActivityTreeOptions options, ProcessActivityCallback callback, IList1& validationErrors)
at System.Activities.WorkflowInspectionServices.GetActivities(Activity activity)+MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext() at System.Linq.Enumerable.ConcatIterator1.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext() at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext()
at System.Collections.Generic.HashSet1.UnionWith(IEnumerable1 other)
at System.Collections.Generic.HashSet1..ctor(IEnumerable1 collection, IEqualityComparer1 comparer) at System.Linq.Enumerable.DistinctIterator1.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at UiPath.Executor.Tracking.TrackingHelpers.GetVariableNames(Activity activity)
at UiPath.Executor.Tracking.TrackingHelpers.TrackVariables(TrackingProfile profile, WorkflowInfo workflowInfo)
at UiPath.Executor.Tracking.DebugTrackingParticipant.RegisterWorkflow(WorkflowInfo workflowInfo)
at UiPath.Executor.DebuggerPlugin.UiPath.Executor.IDebuggerPlugin.RegisterWorkflowTracking(WorkflowInfo workflowInfo)
at UiPath.Executor.Tracking.WorkflowTracking.RegisterWorkflowTracking(WorkflowInfo workflowInfo)
at UiPath.Executor.WorkflowRuntime.RegisterWorkflow(WorkflowInfo workflowInfo)
at UiPath.Executor.RobotRunner.InitWorkflowApplication()
at UiPath.Executor.RobotRunner.ExecuteJob()
"

@ayushi_jain3

The error is file is not found.
Once check the path of excel file.

@ayushi_jain3

I hope your error got solved. Try the above one and let me know the status of it.

I am providing the correct path. Don’t know why it isn’t executing

@ayushi_jain3

Can you share the screenshot of error

Test Sequence.xaml (8.1 KB)

Hi @ayushi_jain3

Try this:

  1. Use Read Range → Output: inputDataTable

  2. Use the “Add Data Column” activity to add the new columns to the DataTable.
    inputDataTable.Columns.Add(“New Column 1”, GetType(String))
    inputDataTable.Columns.Add(“New Column 2”, GetType(String))
    inputDataTable.Columns.Add(“New Column 3”, GetType(String))
    inputDataTable.Columns.Add(“New Column 4”, GetType(String))

  3. Write Range (inputDataTable) → Specify the same sheet name and range as the original data to overwrite the existing sheet with the new column names.