Do you mean your header would contain the headings of search result?
If so, get the headers of the search result and store them in an array.
And then use that array in above logic for displaying the header in the excel sheet.
If so, get the headers of the search result and store them in an array.
And then use that array in above logic for displaying the header in the excel sheet.