将一个图表数据源复制到另一个

时间:2018-08-09 09:08:06

标签: c# powerpoint office-interop com-interop excel-interop

对不起,我的英语

任务

请帮助我完成根据以下逻辑将源图表形状移动到目标图表形状的方法:

  • 将源图表类型分配给目标图表。
  • 将源图表数据评估为目标图表。
  • 所有其他属性都必须保留为目标图表。

开始

using PP = Microsoft.Office.Interop.PowerPoint;
using XL = Microsoft.Office.Interop.Excel;

namespace SoInteropPp
{
    internal static class ChartSamples
    {
        internal static void MoveChart(PP.Shape sourChart, PP.Shape destChart)
        {
            // Validate
            if (sourChart.HasChart == MsoTriState.msoFalse || destChart.HasChart == MsoTriState.msoFalse)
                throw new ArgumentException();

            // Process type.
            destChart.Chart.ChartType = sourChart.Chart.ChartType;

            // Move source chart data source to destination chart.
            var sourBook = sourChart.Chart.ChartData.Workbook as XL.Workbook;
            var destBook = destChart.Chart.ChartData.Workbook as XL.Workbook;

            //...?
        }
    }
}

我的研究

如果我正确理解,则需要

  1. 定义sourBook中的哪个工作表中包含源图表数据。
  2. 定义工作表的哪个范围包含数据源。
  3. 将范围(第2步)复制到目标工作表
  4. 通过destChart将复制的范围分配给destChart.SetSourceData()

问题

我不能(不知道)通过Interop.PowerPoint API实现上述步骤。如何存档这些步骤,或者还有其他方法?

0 个答案:

没有答案