我正在尝试从int的列表和字符串列表中加载数据以使用带有asp.net的epplus库来显示图表,但是当我尝试从int列表加载时,它可以正常工作出现异常:
System.IndexOutOfRangeException:'索引超出了数组的范围。
var workSheet = ep.Workbook.Worksheets.Add("Activité");
// specify cell values to be used for generating chart.
// CountList : list of int
workSheet.Cells[2, 1].LoadFromCollection(CountList);
// add chart of type Pie.
var myChartt = workSheet.Drawings.AddChart("chart", eChartType.CylinderCol);
// Define series for the chart
var seriess = myChartt.Series.Add("A2: A5", "B2: B5");
myChartt.Border.Fill.Color = System.Drawing.Color.Green;
myChartt.Title.Text = "My Chart";
myChartt.SetSize(400, 400);
答案 0 :(得分:2)
问题是由int类型引起的,要覆盖它,你可以传递一个字符串列表:
var workSheet = ep.Workbook.Worksheets.Add("Activité");
List<int> CountList= new List<int>();
List<string> stringList= new List<string>();
foreach (var num in CountList)
{
stringList.Add(num.ToString());
}
// specify cell values to be used for generating chart.
// CountList : list of int
workSheet.Cells[2, 1].LoadFromCollection(stringList);
// add chart of type Pie.
var myChartt = workSheet.Drawings.AddChart("chart", eChartType.CylinderCol);
// Define series for the chart
var seriess = myChartt.Series.Add("A2: A5", "B2: B5");
myChartt.Border.Fill.Color = System.Drawing.Color.Green;
myChartt.Title.Text = "My Chart";
myChartt.SetSize(400, 400);
似乎LoadFromCollection对于字符列表和双精度列表也失败了,所以我想LoadFromCollection期望传递参考值集合。