It is straightforward to export lists to Excel with Export. Can I export a graphic image, too? This does not work:

g = CompleteGraph[4];
fnOut = "Output1.xls";
Export[fnOut, {"Sheet1" -> g}]

Maybe I need to transform g in some way?

  • 1
    $\begingroup$ What do you want to see in Excel? An image or a Plot? $\endgroup$ – Dr. belisarius Jul 5 '12 at 17:54
  • $\begingroup$ Not sure what the difference is. I do not need details of the graphs such as coordinates of the vertices. And I do not need Excel's graphing capabilities. So, image, I suppose. $\endgroup$ – Karsten W. Jul 6 '12 at 16:33

You can export both data and the images using one of several syntax patterns that you find in the docs on XLS format:

enter image description here enter image description here

For example:

 g = CompleteGraph[7];
 {g, {"mySheet1" -> Normal@AdjacencyMatrix[g]}}, {{"Images", "Sheets"}}]


enter image description here

EDIT: Exporting multiple images:

It seems you need at least one sheet (which could be empty) as part of any export. With this restriction,

Export["multipleImages.xls", {CompleteGraph[#] & /@ {5, 7, 9}, {}},
  {{"Images", "Sheets"}}]


Export["multipleImages2.xls", {{}}, "Images" -> (CompleteGraph[#] & /@ {5, 7, 9})] 


  {"Sheets" -> {}, "Images" -> (CompleteGraph[#] & /@ {5, 7, 9})}, "Rules"]

all work to export several images.

  • $\begingroup$ this is very helpful. Do you have an advice how to export several graphs in one Export statement? I studied the docs, but can not figure this out. $\endgroup$ – Karsten W. Jul 6 '12 at 16:31
  • $\begingroup$ @Karsten, I was not able to export only images (without at least one sheet accompanying the images), it seems you need at least one sheet (which could be empty) as part of any export. So, Export["multipleImages.xls", {CompleteGraph[#] & /@ {5, 7, 9}, {}}, {{"Images", "Sheets"}}] or Export["multipleImages2.xls", {{}}, "Images" -> (CompleteGraph[#] & /@ {5, 7, 9})] both work to export several graphs. $\endgroup$ – kglr Jul 6 '12 at 22:49
  • $\begingroup$ Great! I will try on Monday. $\endgroup$ – Karsten W. Jul 6 '12 at 23:07
  • $\begingroup$ aaaaand that puts you to 10k! Let the party begin! We now have 10 10k users $\endgroup$ – rm -rf Jul 13 '12 at 23:56
  • $\begingroup$ @R.M Thank you again! $\endgroup$ – kglr Jul 14 '12 at 2:03

If you need a basic data behind the graph, the AdjacencyMatrix I think is good for tabular formats. This will work:

 Export["graph_data.xls", AdjacencyMatrix[CompleteGraph[13]]]


If you need the image of the graph object, in addition to programmatic way (see @kguler answer) there is an interactive way I personally use often. The steps (on win7):

  • Right click on a graph to copy it

enter image description here

  • In MS Excel open a drop-down under Paste, choose Paste Special and then choose Picture

enter image description here

  • $\begingroup$ I don't think this answers the question. The o/p clearly wanted to Export a graphic image to .xls, not manually import an image from Excel. And kguler's reply clearly proves the statement "... then you should export it as an image" wrong. I'd almost downvote. $\endgroup$ – Andreas Lauschke Jul 5 '12 at 20:36
  • $\begingroup$ @AndreasLauschke Yes kguler answer is cool, I updated my answer due to it. Nevertheless the interactive way I describe is something people often do not know. Some can benefit, as I did when I learned it. $\endgroup$ – Vitaliy Kaurov Jul 5 '12 at 21:23
  • $\begingroup$ An addition: the quality of EMF graphics always depends on the size on screen of the original image because metafiles are sampled at screen resolution fidelity (see my answer here). $\endgroup$ – Alexey Popkov Jul 6 '12 at 9:10
  • $\begingroup$ @AlexeyPopkov True. The easiest way is to drag the outer image frame to larger size if one does everything with the mouse anyway. $\endgroup$ – Vitaliy Kaurov Jul 6 '12 at 12:56
  • $\begingroup$ Thanks for the hint. Actually I want to export several graphs in one Export statement. $\endgroup$ – Karsten W. Jul 6 '12 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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