How to save Excel chart sheet to SVG in C#

A ChartSheet represents a chart sheet. It is a worksheet that contains only a chart. This article will demonstrate how to convert a chart sheet to SVG stream by using Spire.XLS.

Firstly, view the sample Excel worksheets with two chart sheets.

How to save Excel chart sheet to SVG in C#

Convert all the chart sheets to SVG stream:

using System.Drawing.Imaging;
using System.IO;
namespace Convert
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the document from file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");

            //call ToSVGStream(Stream stream) method to save each chart sheet to SVG stream 
            for (int i = 0; i < workbook.Chartsheets.Count; i++)
            {
                FileStream fs = new FileStream(string.Format("chartsheet-{0}.svg", i), FileMode.Create);
                workbook.Chartsheets[i].ToSVGStream(fs);
                fs.Flush();
                fs.Close();
            }


        }
    }
}

Effective screenshot of the two chart sheets to SVG.

How to save Excel chart sheet to SVG in C#

using System.Drawing.Imaging;
using System.IO;
namespace Convert
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the document from file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");

            //get the second chartsheet by name
            ChartSheet cs = workbook.GetChartSheetByName("Chart2");

            //save to SVG stream
            FileStream fs = new FileStream(string.Format("chart2.svg"), FileMode.Create);
            cs.ToSVGStream(fs);
            fs.Flush();
            fs.Close();


        }
    }
}

How to save Excel chart sheet to SVG in C#