EPPlus chart from list of single excel cells. How?

会有一股神秘感。 提交于 2019-12-06 11:55:41

The line with cell names separated by commas is the format you want. Did you specify both the x and y axis range? Maybe show your code where you actually add the series.

You should be using ExcelRange not Address. Like this:

[TestMethod]
public void Chart_From_Cells_Test()
{
    //http://stackoverflow.com/questions/29207020/epplus-chart-from-list-of-single-excel-cells-how
    var existingFile = new FileInfo(@"c:\temp\temp.xlsx");
    if (existingFile.Exists)
        existingFile.Delete();

    using (var pck = new ExcelPackage(existingFile))
    {
        var myWorkSheet = pck.Workbook.Worksheets.Add("Content");
        var ExcelWorksheet = pck.Workbook.Worksheets.Add("Chart");

        //Some data
        myWorkSheet.Cells["A1"].Value = "A";
        myWorkSheet.Cells["A2"].Value = 100; myWorkSheet.Cells["A3"].Value = 400; myWorkSheet.Cells["A4"].Value = 200; myWorkSheet.Cells["A5"].Value = 300; myWorkSheet.Cells["A6"].Value = 600; myWorkSheet.Cells["A7"].Value = 500;
        myWorkSheet.Cells["B1"].Value = "B";
        myWorkSheet.Cells["B2"].Value = 300; myWorkSheet.Cells["B3"].Value = 200; myWorkSheet.Cells["B4"].Value = 1000; myWorkSheet.Cells["B5"].Value = 600; myWorkSheet.Cells["B6"].Value = 500; myWorkSheet.Cells["B7"].Value = 200;

        ExcelRange values = myWorkSheet.Cells["B2,B4,B6"];
        ExcelRange xvalues = myWorkSheet.Cells["A2,A4,A6"];

        const string myTitle = "Chart 1";
        ExcelChart chart1 = ExcelWorksheet.Drawings.AddChart(myTitle, eChartType.Pie);
        chart1.Series.Add(values, xvalues);

        pck.Save();
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!