Message Boards Message Boards

0
|
4341 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

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

2 Replies

Many thanks Rohit!

Posted 3 years ago

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.

POSTED BY: Rohit Namjoshi
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