@@ -8,25 +8,34 @@ class Program
88 {
99 static void Main ( string [ ] args )
1010 {
11+ //Initialize ExcelEngine
1112 using ( ExcelEngine excelEngine = new ExcelEngine ( ) )
1213 {
14+ //Initialize application
1315 IApplication application = excelEngine . Excel ;
16+
17+ //Set the default version as Xlsx
1418 application . DefaultVersion = ExcelVersion . Xlsx ;
1519
16- // Initialize XlsIORenderer
20+ //Initialize XlsIORenderer
1721 application . XlsIORenderer = new XlsIORenderer ( ) ;
1822
19- //Set converter chart image format to PNG
23+ //Set converter chart image format to PNG or JPEG
2024 application . XlsIORenderer . ChartRenderingOptions . ImageFormat = ExportImageFormat . Png ;
2125
26+ //Set the chart image quality to best
27+ application . XlsIORenderer . ChartRenderingOptions . ScalingMode = ScalingMode . Best ;
28+
29+ //Open existing workbook with chart
2230 FileStream inputStream = new FileStream ( Path . GetFullPath ( @"Data/InputTemplate.xlsx" ) , FileMode . Open , FileAccess . Read ) ;
2331 IWorkbook workbook = application . Workbooks . Open ( inputStream ) ;
2432 IWorksheet worksheet = workbook . Worksheets [ 0 ] ;
2533
34+ //Access the chart from the worksheet
2635 IChart chart = worksheet . Charts [ 0 ] ;
2736
2837 #region Save
29- //Saving the workbook
38+ //Exporting the chart as image
3039 FileStream outputStream = new FileStream ( Path . GetFullPath ( "Output/Image.png" ) , FileMode . Create , FileAccess . Write ) ;
3140 chart . SaveAsImage ( outputStream ) ;
3241 #endregion
0 commit comments