2017-08-30 108 views
1

我正在尋找一種方法來隱藏/禁用圖表上的某些類別。 (在Y軸)Excel Interop - 隱藏圖表中的類別

這是如何工作與過濾器:

Filter

有誰知道我可以在.NET中做到這一點使用Excel互操作?

回答

0

我希望我不晚到晚會,因爲這個問題到現在已經有一個月了,但是我猜,遲到總比沒有晚。

如果您知道類別的指數,您可以使用此代碼:

// Replace ActiveChart with your specific chart. 
// The index of the ChartGroup is always 1, 
// unless you have multiple chart groups in your chart. 
var chartGroup = (ChartGroup)_application.ActiveChart.ChartGroups(1); 
var category = (ChartCategory)chartGroup.FullCategoryCollection(Index: 2); 
category.IsFiltered = true; 

如果你只知道這個名字,你需要遍歷類別:

// If you want to skip the already hidden categories, 
// you can use .CategoryCollection() instead of .FullCategoryCollection() two times. 
var categories = (CategoryCollection)chartGroup.FullCategoryCollection(); 
for (int i = 1; i <= categories.Count; i++) 
{ 
    var category = (ChartCategory)chartGroup.FullCategoryCollection(i); 
    if (category.Name == "W2 - 13/01/17") 
     category.IsFiltered = true; 
}