2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Darren KangPosted Jul 30, 2014, 5:02 AM
Hi, as Evaln mention this is a very difficult task to achieve without using any external helpers, unfortunately .NET does not provide any means to accomplish this.
Also I'm not sure why your requirement is not to use any external DLL because as you mention you are already using an external DLL (OpenXML) for chart creation.
Nevertheless first I would suggest you to watch the video on the following link:
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2013/09/26/screen-cast-updating-chart-data-in-wordprocessingml-and-presentationml.aspx
It explains very nicely charting markups which are contained in your XLSX file that has a chart.
After that you need to create a chart renderer, for example you can use GDI+ and map those chart markups with some drawing action and thus create an image.
I must admit I'm not a fan of reinventing the wheel so I would probably use this external .NET DLL for excel type files, it has a free version which is more than capable to achieve this, like the following:
- First I would create the required chart in an excel file with C#:
var file = new ExcelFile();
var sheet = file.Worksheets.Add("Sheet 1");
var chart = sheet.Charts.Add(ChartType.Area, "D1", "H8");
chart.SelectData("A1:C8");
// ...
- Second I would save that chart to an image stream:
using(var stream = new MemoryStream())
{
chart.Format().Save(stream, new ImageSaveOptions(ImageSaveFormat.Png));
// ...
}
- After that I would use that stream to create an Attachment instance...
White EvalnPosted Nov 19, 2012, 12:34 AM