diff --git a/Chart to Image/Chart to Image/.NET/Chart to Image/Chart to Image/Data/InputTemplate.xlsx b/Chart to Image/Chart to Image/.NET/Chart to Image/Chart to Image/Data/InputTemplate.xlsx index 5d08a58f..c4441d2f 100644 Binary files a/Chart to Image/Chart to Image/.NET/Chart to Image/Chart to Image/Data/InputTemplate.xlsx and b/Chart to Image/Chart to Image/.NET/Chart to Image/Chart to Image/Data/InputTemplate.xlsx differ diff --git a/Chart to Image/Chart to Image/.NET/Chart to Image/Chart to Image/Program.cs b/Chart to Image/Chart to Image/.NET/Chart to Image/Chart to Image/Program.cs index 2071e9bf..7527cf42 100644 --- a/Chart to Image/Chart to Image/.NET/Chart to Image/Chart to Image/Program.cs +++ b/Chart to Image/Chart to Image/.NET/Chart to Image/Chart to Image/Program.cs @@ -8,25 +8,34 @@ class Program { static void Main(string[] args) { + //Initialize ExcelEngine using (ExcelEngine excelEngine = new ExcelEngine()) { + //Initialize application IApplication application = excelEngine.Excel; + + //Set the default version as Xlsx application.DefaultVersion = ExcelVersion.Xlsx; - // Initialize XlsIORenderer + //Initialize XlsIORenderer application.XlsIORenderer = new XlsIORenderer(); - //Set converter chart image format to PNG + //Set converter chart image format to PNG or JPEG application.XlsIORenderer.ChartRenderingOptions.ImageFormat = ExportImageFormat.Png; + //Set the chart image quality to best + application.XlsIORenderer.ChartRenderingOptions.ScalingMode = ScalingMode.Best; + + //Open existing workbook with chart FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/InputTemplate.xlsx"), FileMode.Open, FileAccess.Read); IWorkbook workbook = application.Workbooks.Open(inputStream); IWorksheet worksheet = workbook.Worksheets[0]; + //Access the chart from the worksheet IChart chart = worksheet.Charts[0]; #region Save - //Saving the workbook + //Exporting the chart as image FileStream outputStream = new FileStream(Path.GetFullPath("Output/Image.png"), FileMode.Create, FileAccess.Write); chart.SaveAsImage(outputStream); #endregion