I want to export a nested list to Excel. However when I try to do that every column in my list gets exported to a different sheet. I used {} already in the Export statement to combine all colums and have them on one excel sheet. However then my format gets messed up.

When I use Flatten to remove the extra brackets the dates and vales are shown correctly but all data is in one column.

What I would like it to look like is:

enter image description here

How can I fix this?

My input is:

enter image description here


  • 3
    $\begingroup$ you need to show an example of what your original data looks like and what you want it to look like in excel. $\endgroup$
    – george2079
    Jan 10, 2017 at 20:42
  • $\begingroup$ Give us ExportList in formatted so that we can copy it. You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. It is recommended that you browse the Markdown help and How to copy code from Mathematica so it looks good on this site. $\endgroup$ Jan 10, 2017 at 21:48

1 Answer 1


I'm sure that's not the most efficient way, but to get you started...

First I simulate your data:

data = {{{{2016, 4, 1}, 100}, {{2016, 4, 4}, 200}}, {{{2016, 4, 1}, 
     300}, {{2016, 4, 5}, 400}}};
data // MatrixForm

enter image description here

Then after proper flattening etc:

exp = Flatten[{DateObject@#[[1]], #[[2]]} & /@ #] & /@ Transpose@data
(* {{DateObject[{2016, 4, 1}], 100, DateObject[{2016, 4, 1}], 
  300}, {DateObject[{2016, 4, 4}], 200, DateObject[{2016, 4, 5}], 
  400}} *)
Export["somefile.xlsx", exp]

or you can use Apply instead of one Map

exp = Flatten /@ Apply[{DateObject@#1, #2} &, Transpose@data, {2}]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.