I found the following example in the Basic Examples section of this page of the documentation: https://reference.wolfram.com/language/ref/format/XLS.html. It exports 2 data sets, data1
and data2
, into 2 different sheets named Experiment 1 and Experiment 2, of the same spreadsheet, datasets.xls. If you're not able to append new sheets to a spreadsheet after it has been created, you might need to create the spreadsheet with all the sheets outside of your for loop and then add the data to each sheet.
data1 = Table[{t, 9.8*t^2}, {t, 0, 3, .1}];
data2 = Table[{t, 9.8*t^2}, {t, 0, 5, .2}];
Export["datasets.xls",
"Sheets" -> {"Experiment 1" -> data1,
"Experiment 2" -> data2}, "Rules"]
Edit: I understand that your issue arises from the Export
function overwriting the file in question instead of appending to it. For some file types, adding OverwriteTarget->"Append"
to the Export
function helps, although it appears not for Excel sheets. For more basic file types like CSV, you can also use AppendTo
, or OpenAppend
and then Write
. You can try doing this into a CSV and then converting to .xls, or use Henrik's suggestion of keeping all the data and then exporting once at the end.