Column Manipulation

  • To combine the two header rows into one final row of column names.
  • If a column is marked as "Unnamed", it should be skipped, and only the valid sub-header from the second row should be used.
  • You want a question generated where the column name is “Loan Student Repayment”, and possibly others following the same rule.

The image shows a spreadsheet grid containing various column headers related to period, employee tax, employer contributions, loans, deductions, statutory payments, and amounts due to HMRC. (Captioned by AI)

Please give me the Solution

Hey @N.R_Mane,

Read the Excel using Read Range without headers and store it in dtRaw.
Create new column names using LINQ by combining the first two rows, skipping “Unnamed” headers.
Assign these new names back to dtRaw.Columns(i).ColumnName.
Remove the first two rows using dtRaw.Rows(0).Delete() twice and then dtRaw.AcceptChanges().
Now dtRaw will have correct headers like “Loan Student Repayment”.

Let me know if you need anything

1 Like

@N.R_Mane To add header from second row you can use below syntax

1.In For each loop
image

2.To add second row as a header
image

3.In if this below condition will help you to filter out Unnamed
image

  1. In the end use this below linq to filter out columns
    image

Apply this above queries appropriately and update me if you are facing any issue

Regards,
Rajesh Rane

1 Like

Hello @N.R_Mane

You could build it as shown below.
(Using an ExcelFile as an example)

  1. Use Remove Data Row activity with RowIndex 0 to remove empty second row.
  2. Use a For Each activity on dt_ExcelTable.Clone.Columns
  3. Use an If activity to check if currentDataColumn.ColumnName.StartsWith(“unnamed”)
  4. Use a Remove Data Column activity to remove the column from dt_ExcelTable

Download example here: Column Manipulation.xaml (12.6 KB)

Regards
Soren

1 Like

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