我正在尝试获取已存在于Excel工作表中的现有图表的标题。我没有在服务器上安装ms office。所以我正在使用EPPlus库。我能够在工作表中添加新图表,但我想检索现有图表的图表标题。有什么方法可以通过epplus获得它吗?
我尝试了以下代码:
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;
}
}