Adding Column Header if its empty

Hi,

How do I add column headers after transposing my data. Seems like I can’t use any activity to do this

Cheers

Hi @lqxchan

<Read Range Activity>
  Input: "Sheet1"
  Output: dtOriginal




<Invoke Code Activity>
Dim dtTransposed As New DataTable

' Create columns for transposed DataTable
For i As Integer = 0 To dtOriginal.Rows.Count
    dtTransposed.Columns.Add()
Next

' Transpose data
For row As Integer = 0 To dtOriginal.Rows.Count - 1
    Dim newRow As DataRow = dtTransposed.NewRow()
    For col As Integer = 0 To dtOriginal.Columns.Count - 1
        newRow(col) = dtOriginal.Rows(row)(col)
    Next
    dtTransposed.Rows.Add(newRow)
Next

' Store the transposed DataTable
TransposedDataTable = dtTransposed

<Assign>
  To: TransposedDataTable.Columns(0).ColumnName
  Value: "NewHeader1"
<Assign>
  To: TransposedDataTable.Columns(1).ColumnName
  Value: "NewHeader2"
...
<Assign>
  To: TransposedDataTable.Columns(N).ColumnName
  Value: "NewHeaderN"

<Write Range Activity>
  Input: TransposedDataTable
  Sheet: "Sheet2"


Hi @pravallikapaluri

The code does not work as dt is not declared. Is there any other method I can try to input column header as “Invoice 1”, “Invoice 2”… according to the amount of columns generated after transpose

Cheers

Hi @lqxchan

<Assign>
  To: columnCounter
  Value: 1

<For Each col In dtTransposed.Columns>
  <Assign>
    To: col.ColumnName
    Value: "Invoice " + columnCounter.ToString

  <Assign>
    To: columnCounter
    Value: columnCounter + 1

<Write Range Activity>
  Input: dtTransposed
  Sheet: "Sheet2"

@lqxchan Create one template file and append new data to the template file

Hi, @pravallikapaluri

I tried the invoke code method but it does not work. Is there a way where the bot can just add the column name for each column that is being transposed

@lqxchan
Try another method which posted

hi,

There is an error BC30574 regarding late binding for the following activity

To: col.ColumnName Value: "Invoice " + columnCounter.ToString

Hi @lqxchan

After transposing the data you can use the Insert column activity if you are using Excel or you can use the add data column activity if using datatables.

Hope it helps!!

Hi @mkankatala

If I add the insert column activity, it will add a new blank column. But I’m looking at adding the column header/name and keeping the contents of the transposed data

@lqxchan