Export to Excel file with headers?

Hi. I want to export a list from Mathematica to Excel, but would want to be able to plug column names into the Excel file.

Something like this:

aToy={{1,2,3},{4,5,6},{7,8,9}}

headers={"A","B","C"}

and then be able to do something like:

Export["C:\\, "aToy.xls", (*columnNames=headers*)]

In this toy example, it would be very easy to do it manually in the Excel file,
but if you have tens of columns then it is another story…

Is this at all possible? Then, how?
Also, can I name the rows of the excel file?

Thanks in advance,
Francisco

Hi Francisco,

Here is one way

aToy={{1,2,3},{4,5,6},{7,8,9}};
headers={"A","B","C"};

aToy // Prepend[headers] // Export["file.xlsx", #] &

Also, can I name the rows of the excel file?

rowHeaders = {"R1", "R2", "R3"}
headers //= Prepend["R"] (* Have to add another header, can be empty string *)

aToy // Transpose // Prepend[rowHeaders] // Transpose // Prepend[headers] //
 Export["file.xlsx", #] &

You can write a function that takes the data, and headers and generates the right form for export.

Many thanks Rohit!