How can I export a table to Excel - to specific cells, e.g. D1-E2?

Background: I want to compare results, and it's easier to have the results on one spreadsheet.

I'm using Mathematica 6.

This is my notebook so far:

ResultsV = Grid[{  {"result1", result1},  {"result2", result2}}] 
Export["results.pdf", ResultsV]

This table should appear twice in the spreadsheet, as some parameters differ.

Thanks a lot!

  • 5
    $\begingroup$ I suggest you create an Excel file manually, and then use Import["file.xls", "Rules"] and see what you can learn from it. $\endgroup$
    – Mr.Wizard
    Jul 25, 2012 at 13:30

1 Answer 1


For example:

(* some data *)
pts = Range[10]^4;
f1 = Interpolation[pts, InterpolationOrder -> 1];
f2 = Interpolation[pts, InterpolationOrder -> 3];
t1 = Join[{{"x", "f1[]"}}, Table[{x, f1@x}, {x, 1.5, 4.5, 1}]];
t2 = Join[{{"x", "f2[]"}}, Table[{x, f2@x}, {x, 1.5, 4.5, 1}]];
data = Join @@@ Transpose@{t1, t2};

(* Transformation from Excel "A1" notation to indexes *)
at = {FromDigits@ToExpression@Flatten[StringCases[Characters[#], _?DigitQ], 1], 
      FromDigits[Flatten[ToCharacterCode /@ StringCases[Characters[#], _?UpperCaseQ] - 
       First@ToCharacterCode["A"] + 1, 2], Length@CharacterRange["A", "Z"]]} &;

(* Generation of a sparse array with the required block positioning *)
sp[data_List, pos_String] := SparseArray[
                              Flatten@MapIndexed[#2 + at@pos - 1 -> #1 &, data, {2}],  
                            Automatic, ""];

(* export the data to Excel*)
Export["c:\\test2.xls", sp[data, "B3"]]

Mathematica graphics

  • $\begingroup$ How does this show filling e.g. D1-E2? $\endgroup$
    – Mr.Wizard
    Jul 26, 2012 at 2:07
  • $\begingroup$ @Mr.Wizard In a previous incarnation of this answer (you may look at it in the edit history) I posted a way to convert from "excel coordinates" to indexes. As I didn't get a reply from the OP, I am trying now to show him a different thing. Sorry, but if it isn't this one, I am unable to understand what is he looking for. $\endgroup$ Jul 26, 2012 at 2:30
  • $\begingroup$ I believe the idea is to do Export["file.xls", data] and have certain columns filled in; no time now to talk about it though, sorry. $\endgroup$
    – Mr.Wizard
    Jul 26, 2012 at 2:32
  • $\begingroup$ @Mr.Wizard did it. Not sure if this is what the OP wanted, but anyway .. $\endgroup$ Jul 26, 2012 at 2:58
  • 1
    $\begingroup$ I'm new in Mathematica - I still do not understand in detail what you did, belisarius (nevertheless, Thanks, I'll work it out). It may be not exactly what I am looking for: I run my computations for different cases and at the end of the programm, I export the data. Running the file twice (for the second case, eg), I'd like to write the data into the already existing xls file that contains the results of the first case. $\endgroup$ Jul 29, 2012 at 21:44

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.