Support Portal

for ProcessRobot and WinAutomation

Start a new topic
Answered

QueryResult - Headers lost when data moved to Excel

Is there a way to include headers. When using "Write to Excel Worksheet" action and set the %QueryResult% variable to the "Value to Write:" the headers are not shown?


Best Answer

Pieter,


You need to use a 2nd write excel action to write the QueryResults Datatable's - Column Headers (or any Datatable's Column Headers), in the row above the row, that you specified the QueryResults Datatable to start writing in your main write excel action.

The datatable has a property of .Columns .. which is a list variable containing your columns headers of the the datatable (queryresults - datatable, in your case).
You can use a For Each Loop to loop thru the list variable of column headers and write the header columns to your excel, as the row above where you are writing the queryresults datatable.

Example:

Set %columnCounter% = 0
For Each item in  %QueryResults.Columns%  store current item into:  %columnName%

.. Increase by 1  %columnCounter%
.. Write Excel:   Column:  %columnCounter%.  Row: 1  Value: %columnName%
End Loop


Write Excel:   Column:  1.  Row: 2  Value: %QueryResults%



Answer

Pieter,


You need to use a 2nd write excel action to write the QueryResults Datatable's - Column Headers (or any Datatable's Column Headers), in the row above the row, that you specified the QueryResults Datatable to start writing in your main write excel action.

The datatable has a property of .Columns .. which is a list variable containing your columns headers of the the datatable (queryresults - datatable, in your case).
You can use a For Each Loop to loop thru the list variable of column headers and write the header columns to your excel, as the row above where you are writing the queryresults datatable.

Example:

Set %columnCounter% = 0
For Each item in  %QueryResults.Columns%  store current item into:  %columnName%

.. Increase by 1  %columnCounter%
.. Write Excel:   Column:  %columnCounter%.  Row: 1  Value: %columnName%
End Loop


Write Excel:   Column:  1.  Row: 2  Value: %QueryResults%



1 person likes this

Thanks for the quick reply. I ended up using "Write to CSV File" action. Under advance include column names checkbox.


Best regards 

Pieter Jans

DK

Login or Signup to post a comment