'Accessing chart properties (like chart title) via epplus in asp.net

I am trying to get title of an existing chart that is already present in my excel worksheet. i don't have ms office installed on server. So i am using EPPlus library. I am able to add new chart in worksheet but i want to retrieve chart title of an existing chart . Is there any way i can get it via epplus ?

i have tried the following the code :

                    string file = @"c:\test.xlsm";
                    FileInfo exlName = new FileInfo(file);
                    using (ExcelPackage package = new ExcelPackage(exlName))
                    {
                        var logSheet = package.Workbook.Worksheets.SingleOrDefault(x => x.Name == "DEMO CHARTS");  //this worksheet contains chart in it 
                        if (logSheet != null)
                        {
                            var chart = logSheet.Drawings["Chart 1"] as ExcelChart;
                            var title = chart.Title;
                        }
                    }


Solution 1:[1]

enumerate through the drawings collection on your worksheet - make sure the object is an excelchart (not a picture for example) - then query the innerText (or innerXml) to find your title.

            foreach(var drawing in worksheet.Drawings)
            {
                if (drawing is ExcelChart)
                {
                    if (((ExcelChart)drawing).ChartXml.InnerText.Contains("YOUR GRAPH TITLE"))
                    {
            //-- convert and use here...
            var chart = drawing as ExcelBarChart;
                    }
                }
            }

Note: The answer below isn't perfect, as if your chart title is in the innertext for the drawing object (e.g. your chart title is "!") - it won't work, and in that case you will need to use the InnerXML property instead and search it using XDom..

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steve Parker