Clone data table but use only headers and write to excel

Hi everyone. My issue is the following: i have an excel workbook and use a read range activity to output in a data table dt1. I’m trying to make another data table dt2 with the same structure as dt1 but keep only the headers and write them in another excel workbook. i did the following:

  1. Read Range Activity - Input:Excel Workbook 1 Output: dt1
  2. Assign activity - dt2 = dt1.clone()
  3. Write Range Activity - Excel Workbook 2

The Excel Workbook 2 is empty without any headers.

I need to mention the fact that in both read range and write range activity the “Add Headers” option is ticked.

Your help will be highly appreciated!

Hi welcome to the community!
Take a look more closely at your process and your write range, it should work fine… BUT if you dont have any data in dt2, you should not write anything :wink:

HI @RaduNRV

You can try something like this…

You can assign the actual values of DT1 to DT2 after cloning…

Dt2 = Dt1

After that, you can use the Clear DataTable activity to clear the records of the datatable 2 except the headers and then do a write range…

See whether this works

the Excel 1 has data and headers. After cloning the dt1 which is the output of the excel 1 reading, dt2 should have its structure but when writing in Excel 2 it’s empty, no headers whatsoever. i don’t understand what i’m doing wrong.

it doesn’t work. My Excel 2 workbook still has no headers.

1 Like

you are not doing anything wrong, but you did not understand what i told you… since dt2 has not data, write range wont do anything… why would you go this way if you only want a new excel sheet with the headers, you can just use write cell with each column name instead…
or just add an empty row in your dt2

4 Likes

Oh, now i get you. After the clone, even though it preserves the structure, since it’s empty when i do the write range it writes nothing, not even the headers right?

1 Like

Yes… exactly… so if you want to write the headers, just add an empty row the the datatable and write it :slight_smile:

Thanks for all your help guys. I’ll add a new row to dt2 and see if it works.

Much appreciated!

1 Like

It works !!! Thanks again guys!

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