Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-在Word中添加图表_C#_Charts_Vsto_Office Interop - Fatal编程技术网

C#-在Word中添加图表

C#-在Word中添加图表,c#,charts,vsto,office-interop,C#,Charts,Vsto,Office Interop,我正在开发一个VSTO插件,它应该与Word的所有版本兼容 我编写了以下代码,在Word文件中添加了一个图表 private void AddToNewChart() { // add chart Word.Chart chart; Word.InlineShape inlineShape; string chartType = ((ComboBoxItem)cmbChartType.SelectedItem).Content.ToString();

我正在开发一个VSTO插件,它应该与Word的所有版本兼容

我编写了以下代码,在Word文件中添加了一个图表

private void AddToNewChart()
{
     // add chart
    Word.Chart chart;
    Word.InlineShape inlineShape;
    string chartType = ((ComboBoxItem)cmbChartType.SelectedItem).Content.ToString();

    if (chartType.Equals("Pie Chart"))
        inlineShape = currDoc.InlineShapes.AddChart(Core.XlChartType.xlPie, Type.Missing);
    else
        inlineShape = currDoc.InlineShapes.AddChart(Core.XlChartType.xlColumnClustered, Type.Missing);

    inlineShape.AlternativeText = newChartName + "__TabularChart";
    chart = inlineShape.Chart;

    // get references
    dynamic chartWB = chart.ChartData.Workbook;
    dynamic chartTable = chartWB.Sheets[1].ListObjects("Table1");
    chartTable.DataBodyRange.ClearContents();
    dynamic chartRange = chartTable.Range.Resize[2, 2];

    // update data
    chartTable.Resize(chartRange);
    chartRange.Cells[chartRange.Rows.Count, 1] = namedRange;
    chartRange.Cells[chartRange.Rows.Count, 2] = excelValue;
    chartRange.Cells[chartRange.Rows.Count, 9] = string.Format("{0}->{1}->{2}", fileId, worksheet, namedRange);

    this.FillChartDropdown();

    chartWB.Close(1);
    chartWB.Application.Quit();
    chartWB.Application = null;
}
这非常适用于Office 2010, 但在Office 2013中,Excel过程不会在末尾终止,因此添加图表后,单词会完全冻结


那么,我应该怎么做才能在结束时终止Excel进程?

Excel进程在这方面扮演什么角色?@Chris:当我更改图表源数据时,Excel会自动打开。即使我们手动操作,也会发生这种情况