Copy only headers from one excel to another

Hi,

I wanted to simply copy just headers from one excel to another - I tried it with:

  1. Invoke method
  2. copying the whole table and then deleting every single row except of the headers (with Remove Data Row Activity and it does not seem to work. - always getting the empty excel sheet
  3. creating headers manually (with Build Datatable) and again when I want to put it inside the other excel sheet - I get the empty sheet (Just in A1 cell is written: “Column 1”)

Important: When I use Activity: Output datatable (just to print my datatable to see whether I have good values and whether my table is empty)-> I actually get the right values (my headers). But then again in excel - nothing…

I am desparate, does anyone have solution for this?

@ajlakasic use clone method it may work. destinationdataTableName=SourceDatatableName.clone

Hey, I tried .clone and .clear - both… but again the same result (“column1” in the A1 Cell)…

@ajlakasic after building datatable with clone add data to that datatable and write to excel sheet atlast, it will work.

@Manjuts90, can you please explain me detailed?
You mean - I should have something like this:

To assign headers to a variable headers (type: Datatable) and then to write it into excel?
(to mention also this: my target excel is empty at the beginning)


Thank you very much for your help!

@ajlakasic before writing to excel add data to that datatable and then write to excel it will work

I still don’t get it :frowning:
How do you mean to add data to the datatable? I do not have any datatable created… My excel is empty.
I defined datatable headers and assigned the sourcedt.Clone() to it… afterwards I wrote it in excel…

do you mean there is another way to add data to datatable?

I feel like the other solutions, while valid, are overly complicated. Can you read range (“A1:Z2”) Z being the last column where there is a header) into a datatable, leave the add headers option checked, and write range into the new sheet in A1? Then write cell/value “” into cells (“A2:Z2”) to clear that second row of data, leaving only the headers. You might be able to just specify the row (“2:2”).

2 Likes

@ajlakasic use below code it copy only headers, change the array to ur required size based on ur columns

copyOnlyHeaders.xaml (9.1 KB)

Maybe you can write the empty datatable(only with the column titles ) into a csv file.
And then use [copy file ] utility to copy the [.csv] to [.xls] file.
That’s will show the column titles when you open the [.xls] file.

@KEntwistle Thanks! It worked at the end :slight_smile: I had a way more rows than 2, but i adjusted it, and it works… thank you :slight_smile:

1 Like