# How to save the results in an identical Excel file (.xls) in each iteration of a Do loop

Assume the following code (Below code is just an example to clearly illustrate my problem):

Res = {};
Iterations = 5;

Do[
Results = AppendTo[Res, i^2]
, {i, 1, Iterations}];


I have 2 questions:

1. I want to save the results in each iteration in an identical excel file (.xls file). In the end, when the iterations are finished, I will have one Excel file with all the results in it.

2. I tried to make the code more faster and elegant using Scan[] , but I failed to do it and I couldn't do that.(It is good to mention that I am just a rookie Mathematica programmer and I don't have much experience in it!).

I'm not sure if it's possible to export data to a pre-existing Excel file. Personally, I'd collect the results from the loop and export them at the end. Also, Do is in no way a recursive construct. Are you sure you mean recursive? –  Oleksandr R. Apr 30 '14 at 8:23
the standard Export for excel files can only write content in one go. Of course you can completely overwrite the file for each line, which is inefficient but probably not too problematic. Other than that I see the following possibilities: write to a text file (or CSV) line by line, for these appending is simple and efficient. Depending on the data, you won't loose much compared to an excel file. If you really need excel, you could use NETLink to do what you want, if you search for "NET excel" you'll find many Q+A to start... –  Albert Retey Apr 30 '14 at 8:38