/// <summary>
/// 在当前sheet中插入图表
/// </summary>
/// <param name="range">数据源</param>
/// <param name="xlChartType">图类型</param>
/// <param name="chartTitle">标题</param>
/// <param name="chartLeft">左</param>
/// <param name="chartTop">上</param>
/// <param name="chartWidth">宽</param>
/// <param name="chartHeight">高</param>
public void InsertChart(string range, XlChartType xlChartType, string chartTitle, double chartLeft, double chartTop, double chartWidth, double chartHeight)
{
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)myExcel.ActiveSheet;
ChartObjects charts = (ChartObjects)worksheet.ChartObjects(Type.Missing);
ChartObject chartObj = charts.Add(chartLeft, chartTop, chartWidth, chartHeight);
Chart chart = chartObj.Chart;
chart.Legend.Clear();
chart.ChartType = xlChartType;
Range rg = worksheet.get_Range(range, Type.Missing);
chart.SetSourceData(rg, Type.Missing);
if (chart.HasTitle)
{
chart.ChartTitle.Text = chartTitle;
}
else
{
chart.HasTitle = true;
chart.ChartTitle.Text = chartTitle;
}
}