Exporting Dundas Charts to Aspose.Cells

Dundas charts are simply awesome. What I found problematic at first was having to save these charts to temporary files in order to export the image into another utility (Excel doc, PPT, doc, etc). I did a bit of digging and it is extremely simple to do so:

  1.            // save and add image to export
  2.             MemoryStream ms = new MemoryStream();
  3.             chart.Save(ms, ChartImageFormat.Png);

And thats it. You now have the image in the MemoryStream for use anywhere (to write to a file it you want as well). This prevents saving the document to the file system and having to worry about permissions for writing in IIS, meaning less to maintain.

In my particular scenario I was exporting the image into Aspose.Cells -> which is an Excel Export Utility assembly. Here is how that was accomplished:

  1.            Workbook workbook = new Workbook();
  2.             Worksheet worksheet = workbook.Worksheets[0];
  3.             int picIndex = worksheet.Pictures.Add(1,2,ms);
  4.             Picture pic = worksheet.Pictures[picIndex];
  5.             pic.IsLockAspectRatio = true;
  6.             pic.Placement = PlacementType.Move;

All you have to do is essentially pass it the stream (in our case its MemoryStream). The rest of the code is Aspose.Cells specific API code.

Leave a Reply