Interface ISlicers
Respresents the slicer collection of the worksheet
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Base.dll
Syntax
public interface ISlicers : IEnumerable
Properties
Count
Gets the number of slicers in the worksheet.
Declaration
int Count { get; }
Property Value
Type |
---|
System.Int32 |
Examples
Following code illustrates how to get the slicer count from the worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("Slicer.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
int count = worksheet.Slicers.Count;
workbook.SaveAs("Slicer.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Item[Int32]
Returns the slicer object based on the given index.
Declaration
ISlicer this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Property Value
Type |
---|
ISlicer |
Examples
Following code illustrates how to get slicer object based on the given index.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("Slicer.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
ISlicer slicer = worksheet.Slicers[0];
workbook.SaveAs("Slicer.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Methods
Add(IListObject, Int32, Int32, Int32)
Creates a slicer using the provided column index of the table
Declaration
int Add(IListObject table, int index, int row, int column)
Parameters
Type | Name | Description |
---|---|---|
IListObject | table | Represents the table object. |
System.Int32 | index | Represents the column index of the table. |
System.Int32 | row | Represents the top row for the slicer. |
System.Int32 | column | Represents the left column for the slicer |
Returns
Type | Description |
---|---|
System.Int32 | Returns an index of the slicer |
Examples
The following code illustrates how a slicer can be created in a worksheet using the given table in the worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("Sample.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
IListObject table = worksheet.ListObjects[0];
//Add a new slicer to the worksheet.
int index= worksheet.Slicers.Add(table, 2, 3, 5);
ISlicerCacheItems cacheItems = worksheet.Slicers[0].SlicerCache.SlicerCacheItems;
int itemscount = cacheItems.Count;
ISlicerCacheItem item = cacheItems[0];
string value = item.Value;
Item. IsSelected = false;
//Name of the slicer
ISlicer slicer = worksheet.Slicers[0];
string name = slicer.Name;
slicer.Name = "Sample Slicer";
//Caption name of the slicer
slicer.Caption = "Product Details";
//Displays the header
slicer.DisplayHeader = true;
slicer.SlicerStyle= ExcelSlicerStyle.SlicerStyleDark1;
slicer.Top = 20;
slicer.Left = 200;
//Height and width of the slicer
slicer.Width = 90;
slicer.Height = 90;
//Height and width of the buttons inside the slicer
slicer.SlicerItemHeight = 30;
slicer.SlicerItemWidth = 30;
//Number of columns inside the slicer
slicer.NumberOfColumns = 2;
slicer.SlicerCache.CrossFilterType = SlicerCrossFilterType.HideItemsWithNoData;
slicerCache.IsAscending = true;
workbook.SaveAs("Slicer.xlsx");
workbook.Close();
excelEngine.Dispose();
}
Remove(ISlicer)
Removes a specified slicer from the slicer collection.
Declaration
void Remove(ISlicer slicer)
Parameters
Type | Name | Description |
---|---|---|
ISlicer | slicer | Slicer to be removed |
Examples
Following code illustrates how to remove a slicer from the worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("Slicer.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
ISlicer slicer = worksheet.Slicers[0];
//Remove the slicer from the worksheet
worksheet.Slicers.Remove(slicer);
workbook.SaveAs("Slicer.xlsx");
workbook.Close();
excelEngine.Dispose();
}
RemoveAt(Int32)
Removes a slicer at specified index from the slicer collection
Declaration
void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Index of the slicer to be removed |
Examples
Following code illustrates how to remove a slicer from the worksheet.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open("Slicer.xlsx");
IWorksheet worksheet = workbook.Worksheets[0];
ISlicer slicer = worksheet.Slicers[0];
//Remove the slicer from the worksheet
worksheet.Slicers.RemoveAt(0);
workbook.SaveAs("Slicer.xlsx");
workbook.Close();
excelEngine.Dispose();
}