Exporting Excel Charts as Images

扶醉桌前 提交于 2019-12-05 12:58:52

VBA, but same idea would likely work for C#...

Dim co As ChartObject, sht As Worksheet, x As Long
x = 1
Set sht = ThisWorkbook.Sheets("Sheet1")
For Each co In sht.ChartObjects
    Application.Goto co.TopLeftCell, True
    co.Chart.Export "C:\_stuff\test\chart" & x & ".jpg", "JPG", False
    x = x + 1
Next co

I found the following worked for me

            foreach (Excel.ChartObject co in chartObjects)
            {
                co.Select();
                Excel.Chart chart = (Excel.Chart)co.Chart;
                chart.Export(exportPath + @"\" + chart.Name + ".png", "PNG", false);
            }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!