1
我想在Excel中生成兩個圖表。這是我生成第一個代碼的代碼,然後我想用另一個範圍在同一個文檔中再生成一個代碼。C#在excel中生成多個圖表
Range chartRange;
ChartObjects xlCharts = (ChartObjects)ws.ChartObjects(Type.Missing);
ChartObject myChart = (ChartObject)xlCharts.Add(10, 80, 300, 250);
Chart chartPage = myChart.Chart;
chartRange = ws.get_Range("A4", "AZ4");
chartPage.ChartType = XlChartType.xlLineMarkers;
chartPage.HasTitle = true;
chartPage.ChartTitle.Text = "Lägenhetstyp 1";
chartPage.HasLegend = false;
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = XlChartType.xlColumnClustered;
就是這樣的。
Range chartRange;
//First Chart
ChartObjects xlCharts = (ChartObjects)ws.ChartObjects(Type.Missing);
ChartObject myChart = (ChartObject)xlCharts.Add(10, 80, 300, 250);
Chart chartPage = myChart.Chart;
chartRange = ws.get_Range("A4", "AZ4");
chartPage.ChartType = XlChartType.xlLineMarkers;
chartPage.HasTitle = true;
chartPage.ChartTitle.Text = "Chart 1";
chartPage.HasLegend = false;
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = XlChartType.xlColumnClustered;
//Second chart
ChartObjects xlCharts = (ChartObjects)ws.ChartObjects(Type.Missing);
ChartObject myChart = (ChartObject)xlCharts.Add(10, 80, 300, 250);
Chart chartPage = myChart.Chart;
chartRange = ws.get_Range("A8", "AZ8");
chartPage.ChartType = XlChartType.xlLineMarkers;
chartPage.HasTitle = true;
chartPage.ChartTitle.Text = "Chart 2";
chartPage.HasLegend = false;
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = XlChartType.xlColumnClustered;
http://stackoverflow.com/questions/6968630/creating-multiple-excel-chart-objects-using-c-sharp – Amit 2014-12-09 11:28:14
什麼是您的實際問題?你已經說明了你已經做了什麼,但哪些不起作用?或者你需要什麼不同,你需要幫助? – BG100 2014-12-09 11:48:24
問題解決。見下面的解決方案。謝謝你回答我的問題:) – 2014-12-09 11:50:45