我需要创建一个‘漏斗图’在excel中通过C#使用互操作。直接使用Excel有一个“漏斗图”的选项,但通过后端;枚举没有“漏斗图”的选项。
下面是枚举的链接:
我还尝试在Excel中更改图表类型的同时记录宏,但当我查看宏中的VB代码时,我发现没有用于更改图表类型的代码。
这是使用Excel Interop时的限制吗?有没有其他方法可以做到这一点?
任何帮助都将不胜感激。
发布于 2019-07-23 18:08:54
以下是我正在使用的替代方案:
// 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);图表类型为:金字塔柱堆叠(三维堆积柱)
https://stackoverflow.com/questions/57161037
复制相似问题