I need to export this into a table.

I need to export this into a table, and along with that, the headers should also come together.

And this is my code. What should I do in this code so that any list gets exported into a table?

The Excel export will export all the columns into an Excel sheet and its cells. This should be the result you’re seeing with your code. We do not support Excel table generation, that would need to be configured in Excel afterwards.