我需要使用excel.interop生成一些折线图,我想为Y轴值设置文字。
Dictionary<string, int> data = new Dictionary<string, int>();
data.Add("abc", 1);
data.Add("def", 2);
data.Add("ghi", 3);
data.Add("jkl", 4);
data.Add("mno", 5);
var application = new excel.Application();
var workbook = application.Workbooks.Open(docName);
var worksheet = workbook.Worksheets[1] as excel.Worksheet;
var charts = worksheet.ChartObjects() as excel.ChartObjects;
var chartObject = charts.Add(60, 10, 300, 300);
var chart = chartObject.Chart;
chart.ChartType = excel.XlChartType.xlLine;
chart.Location(excel.XlChartLocation.xlLocationAsObject, worksheetName);
var seriesCollection = (excel.SeriesCollection)chart.SeriesCollection();
var series = seriesCollection.NewSeries();
series.Values = data.Keys.ToArray();
series.XValues = data.Values.ToArray();
series.Name = "test";
workbook.Save();
但这是我的结果(series.Values只包含0和#39;值)。