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
- Use the “Invoke Method” activity and configure it . Refer below images as a configuration example
Approach 3: Inserting Columns Using Excel Activities
- Utilize UiPath’s Excel activities like “Insert Column” to add the columns directly.
- Specify the position of the new columns and provide names as needed.
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
- Create a template Excel file with the required columns pre-defined.
- Use this template in your automation, which will ensure the structure is maintained every time you run the process.
Please find All the approaches in the below Zip File
Adding_Column.zip (64.6 KB)
Hope it helps you!
Regards,
Vikas M