Add one column to a data table while writing into excel

  1. I am fetching a data data base, i need to add one column “Date”,
  2. datarows will be dynamic, so for all the data rows i need to add todays date under a Date column

Database datatable
image

What I am Expecting

image

Thanks.

Hi @ManjunathReddy
NewProcess.zip (172.8 KB)

Hi @ManjunathReddy

Use Add Data Column activity

image

Regards,

Hi @ManjunathReddy ,
You can try add data column
image

Hi @ManjunathReddy

=> Use the Use excel file activity and pass the excel path.
=> Inside Use excel file activity place the Insert column activity. Insert the Column “Date”
=> After Insert column activity place the For each excel row to iterate the rows in the excel.
=> Inside for each place the assign activity to store the now datetime in a variable
- Assign → TodayDate = Now.Date.toString(“dd-MM-yyyy”)
=> After the assign activity place the write cell activity to write the TodayDate variable in to the all rows in date column.
→ In the where to write field give the CurrentRow.ByField(“Column name”)

Check the below workflow for better understanding

Hope it helps!!

Hi @ManjunathReddy

  1. Use read range to read the excel sheet to datatable dtData
  2. Simply use Assign activity to add the data column to datatable:
dtData = (From row In dtData.AsEnumerable()
          Let newRow = row.ItemArray.Append(DateTime.Now.ToString("dd-MM-yy")).ToArray()
          Select dtData.Rows.Add(newRow)).CopyToDataTable()
  1. Use write range write datatable to excel.

Hope it helps.

Hi @ManjunathReddy

Check this
NewProcess.zip (172.8 KB)

@ManjunathReddy

  1. Add Column activity to add one Column.
  2. Add one assign activity.

UpdatedDT = For Each row As DataRow In dtData.Rows
row(“ColumnName”) = DateTime.Now.ToString(“dd-MM-yyyy”)
Next

@raja.arslankhan

Thanks its working fine.

How to add column at position(column0)?

Thanks

@ManjunathReddy
I have specified the position of the column using the method setOrdinal in the invoke method activity:

The DataColumn.SetOrdinal(Int32) method changes the ordinal or position of the DataColumn to the specified ordinal or position.

When you change a column’s ordinal, the column is moved to the new position in the collection of columns. Any columns between the previous and new ordinal will be renumbered, to adjust for a column’s new ordinal.

learn.microsoft.com

DataColumn.SetOrdinal(Int32) Method (System.Data)

Changes the ordinal or position of the DataColumn to the specified ordinal or position.

@ManjunathReddy
we can’t add column specific position but after adding column we can change their position through Invoke Method

@ManjunathReddy If your problem solved, please mark it as a solution

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