Reorder data columns

I have an Excel file and a data table that I need to add to it. However, the table’s columns don’t directly match those in the Excel file, so they need to be reordered. For example, column H of the data table needs to be placed in column D of the Excel file, and so on for other columns.

How can I do this?

@alexis.mendoza.rpa

you can use the following expression with column names in order you need

use assign with

dt = dt.DefaultView.ToTable(false,{"Col1","Col2"})

{"Col1","Col2"} - here you can specify the column names you need and in the order you need so that the columns are re arranged in datatable

cheers

Can I write more than 2 columns?

1 Like

@alexis.mendoza.rpa

yes you can write any number..just for example I have written 2

cheers

1 Like

hi, @alexis.mendoza.rpa

  1. Use Assign or Invoke Code to reorder columns by their index:
dt.Columns("ColumnH").SetOrdinal(3)

This Moves ColumnH to Excel’s column D position (index 3)

Repeat for other columns as needed.

  1. Use Write Range activity to write the reordered DataTable to Excel.

edit- Also you refer to this

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