Is it possible to export to .xlsx with table headings?

Hi,

I recently tried to export a matrix with headings as a .xlsx file. However when I opened the file, I noticed that my headings were missing.
Is it possible to export with headings? I’ve check online and come up empty as to why mine went away.

Thanks,

You should have no problems exporting the headers. If you show part of your code it will be easier to help you.

Sure,

I’ll use the example from Mathematica’s Help Documentation as it much simpler than my actual code.

x = TableForm[{{a, b}, {c, d}, {e, f}}, 
  TableHeadings -> {{"r1", "r2", "r3"}, {"c1", "c2"}}]
Export["x.xlsx", x, "XLSX"]

When I export this, I do not export the headings along with the table.

I see. To my knowledge you should export lists rather than formated data. I assume that Grid and TableForm are recognized by Export but maybe the options are creating the problem. I recommend you to do something linke this to reshape your dataset before exporting:

addExportableHeadings[data_, headings_] := 
Transpose@ Prepend[Transpose@Prepend[data, headings[[2]]], headings[[1]]];
data = {{a, b}, {c, d}, {e, f}};
headings = {{"", "r1", "r2", "r3"}, {"c1", "c2"}};
addExportableHeadings[data, headings]

Problem Solved!

Thank you! The solution that have posted works wonderfully!

Cheers!