簡體   English   中英

如何使用C#Interop在Excel中創建漏斗圖?

[英]How to create a Funnel Chart in Excel with C# Interop?

我需要使用Interop通過C#在excel中創建一個“漏斗圖”。 直接使用Excel,可以通過后端選擇“漏斗圖”。 枚舉沒有以下選項:“漏斗圖”。

這是枚舉上的鏈接:

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

我還嘗試了在Excel中更改圖表類型時記錄宏,但是當我查看宏中的VB代碼時; 我找不到更改圖表類型的代碼。

使用Excel Interop時是否有限制? 我還有另一種方法可以實現這一目標嗎?

任何幫助將不勝感激。

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

// 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);

圖表類型為:金字塔列堆疊(3-D堆疊列)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM