Articles in this section
Category / Section

Is chart to image conversion supported in .net framework 3.5?

1 min read

No. Chart to image conversion is not supported in .Net framework 3.5. Chart to image conversion is supported from .Net Framework 4.0 and higher versions. The following code snippets shows how to converting an Excel Chart to an image using the ExcelChartToImageConverter class.

C#

ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.ChartToImageConverter = new ChartToImageConverter();
application.ChartToImageConverter.ScalingMode = ScalingMode.Normal;
MemoryStream chartStream = new MemoryStream();
string inputFile = Server.MapPath("App_data/input.xls");
IWorkbook workbook = application.Workbooks.Open(inputFile, ExcelOpenType.Automatic);
IWorksheet sheet = workbook.Worksheets[0];
workbook.Worksheets[0].Charts[0].SaveAsImage(chartStream);
chartStream.Position = 0;
System.Drawing.Image img = System.Drawing.Image.FromStream(chartStream);
string outputFile = Server.MapPath("Output/Convertedimage.png");
img.Save(outputFile);   
workbook.Close();
excelEngine.Dispose();     

VB

Dim excelEngine As ExcelEngine = New ExcelEngine()
Dim application As IApplication = excelEngine.Excel
application.ChartToImageConverter = New ChartToImageConverter()
application.ChartToImageConverter.ScalingMode = ScalingMode.Normal
Dim chartStream As MemoryStream = New MemoryStream()
Dim inputFile As String = Server.MapPath("App_data/input.xls")
Dim workbook As IWorkbook = application.Workbooks.Open(inputFile, ExcelOpenType.Automatic)
Dim sheet As IWorksheet = workbook.Worksheets(0)
workbook.Worksheets(0).Charts(0).SaveAsImage(chartStream)
chartStream.Position = 0
Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(chartStream)
Dim outputFile As String = Server.MapPath("Output/Convertedimage.png")
img.Save(outputFile)
workbook.Close()
excelEngine.Dispose()

 

The sample illustrating this behavior can be downloaded here.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied