【问题标题】:How to create a Funnel Chart in Excel with C# Interop?如何使用 C# 互操作在 Excel 中创建漏斗图?
【发布时间】:2019-07-23 18:42:36
【问题描述】:

我需要使用 Interop 通过 C# 在 excel 中创建一个“漏斗图”。直接使用 Excel 有一个“漏斗图”选项,但通过后端;枚举没有选项:“漏斗图”。

这是枚举的链接:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.xlcharttype?view=excel-pia

我也尝试在 Excel 中更改图表类型时录制宏,但是当我查看宏中的 VB 代码时;我找不到更改图表类型的代码。

这是使用 Excel 互操作时的限制吗? 还有其他方法可以实现吗?

任何帮助将不胜感激。

【问题讨论】:

    标签: c# excel-interop


    【解决方案1】:

    这是我正在使用的替代方法:

    // Chart
    Microsoft.Office.Interop.Excel.ChartObjects mainChartObjects = (Microsoft.Office.Interop.Excel.ChartObjects)pivotWorksheet.ChartObjects();
    Microsoft.Office.Interop.Excel.ChartObject mainChartObject = (Microsoft.Office.Interop.Excel.ChartObject)mainChartObjects.Add(0, 0, 500, 500);
    Microsoft.Office.Interop.Excel.Chart mainChart = (Microsoft.Office.Interop.Excel.Chart)mainChartObject.Chart;
    
    ExcelWorkbook.ActiveSheet.Range(pivotTableStartRange, pivotTableEndRange).Select();
    Microsoft.Office.Interop.Excel.Range fullPivotRange = excelWriter.ExcelWorkbook.ActiveSheet.Range(pivotTableStartRange, pivotTableEndRange);
    
    mainChart.SetSourceData(fullPivotRange);
    
    // Set Chart Type
    mainChart.PlotArea.Select();
    mainChart.ChartArea.Select();
    mainChart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlPyramidColStacked;
    mainChart.ChartStyle = 419;
    
    // Plot By
    mainChart.PlotBy = Microsoft.Office.Interop.Excel.XlRowCol.xlRows;
    
    // Remove 3D Rotations
    Excel.ActiveChart.PlotArea.Select();
    Excel.Selection.Format.ThreeD.FieldOfView = 5;
    Excel.Selection.Format.ThreeD.RotationX = 0;
    Excel.Selection.Format.ThreeD.RotationY = 90;
    
    // Legend
    Excel.ActiveChart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementLegendBottom);
    

    图表类型为:Pyramid Column Stacked(3-D Stacked Column)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多