A chart sheet is a separate worksheet that only contains chart, at some times we may need to convert chart sheet to image. This article is going to elaborates how we can convert a chart sheet to image using Spire.XLS.
Screenshot of the Chart sheet:
Detail steps:
Step 1: Instantiate a Workbook object and load the excel file.
Workbook workbook = new Workbook(); workbook.LoadFromFile("Input.xlsx");
Step 2: Get the first chart sheet.
ChartSheet chartSheet = workbook.Chartsheets[0];
Step 3: Save the chart sheet to image and save the image to disk.
Image image = workbook.SaveChartAsImage(chartSheet); image.Save("ChartSheet.png", ImageFormat.Png);
Output image:
Full code:
using System.Drawing.Imaging; namespace Convert { class Program { static void Main(string[] args) { //Instantiate a Workbook object Workbook workbook = new Workbook(); //Load the excel file workbook.LoadFromFile("Input.xlsx"); //Get the first chart sheet ChartSheet chartSheet = workbook.Chartsheets[0]; //Save the chart sheet as image Image image = workbook.SaveChartAsImage(chartSheet); //Save image image.Save("ChartSheet.png", ImageFormat.Png); } } }