Adding a 2 columns between columns


Hello Community!

I’m working with an Excel sheet and need some help! I want to add two new columns:

  1. A column named “Today” between “PO No” and “Invoice Qty”.

  2. Another column named Pending qty will be added after Capex/Opex column.

Does anyone have tips or steps on how to do this efficiently? Thanks in advance!

Hi @Priyesh_Shetty You can achieve this using invoke method activity set ordinal method

In the invoke method parameter you can pass the index where you want to add columns

please find below screenshot where I had same challenge to add columns in between


Hope this will help you

Happy Automation!

Hi @Priyesh_Shetty

Can you try the below

Input:

Output:

Regards,

@Akash_Javalekar1 can you explain more about invoke method,because i want to add 2 columns

Hi @Priyesh_Shetty as per your requirement you can set the index at which position you want to add and pass the column name and index parameter as per your requirement

I have attached workflow solution

Add_Column.zip (46.5 KB)

Let me know if it’s working

Thank You!

Hey @Priyesh_Shetty ,

You can add new columns in your Excel sheet using various approaches. Here are five methods you might consider:

Approach 1: Default View

  • Add the 2 columns - “Today” and “Pending qty” using “Add Data Column” Activity
  • Set your Assign block as following image

dt_input.DefaultView.ToTable(False,"PO NO","Today","INVOICE QTY","CAPEX/OPEX","Pending qty")

Approach 2: Set Ordinal - Invoke Method

Approach 3: Inserting Columns Using Excel Activities

Approach 4: Invoke Code

  • Use the “Invoke Code” activity to write a small snippet of VB.NET code to insert columns programmatically.
Try
    Dim todayColumn As New DataColumn("Today", GetType(String))
    dtData.Columns.Add(todayColumn)
    dtData.Columns("Today").SetOrdinal(1) ' Adjust "1" to set it between "PO No" and "Invoice Qty"

    Dim pendingQtyColumn As New DataColumn("Pending qty", GetType(String))
    dtData.Columns.Add(pendingQtyColumn)
    dtData.Columns("Pending qty").SetOrdinal(4) ' Adjust "5" to set it after "Capex/Opex"

Catch ex As Exception
    Console.WriteLine(ex.Message)
End Try

Approach 5: Template File

Please find All the approaches in the below Zip File

Adding_Column.zip (64.6 KB)

Hope it helps you!
Regards,
Vikas M

2 Likes

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