Message Boards Message Boards

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

Posted 11 years ago
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,
POSTED BY: Pat Mac
4 Replies
You should have no problems exporting the headers.  If you show part of your code it will be easier to help you.
POSTED BY: Ariel Sepulveda
Posted 11 years ago
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.
POSTED BY: Pat Mac
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]
POSTED BY: Ariel Sepulveda
Posted 11 years ago
Problem Solved!

Thank you! The solution that have posted works wonderfully!

Cheers!
POSTED BY: Pat Mac
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract