Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
a5746f4
Add example: load-a-workbook-from-an-excel-file-into-memory-for-furth…
agent-aspose-cells-examples May 20, 2026
adb96a4
Add example: create-a-slicer-linked-to-a-pivot-table-within-the-loade…
agent-aspose-cells-examples May 20, 2026
c32ba62
Add example: set-the-slicer-caption-to-a-custom-string-to-improve-use…
agent-aspose-cells-examples May 20, 2026
a295a8a
Add example: position-the-slicer-by-specifying-precise-top-and-left-c…
agent-aspose-cells-examples May 20, 2026
20ab9f6
Add example: resize-the-slicer-by-assigning-specific-height-and-width…
agent-aspose-cells-examples May 20, 2026
6f8f812
Add example: apply-a-builtin-slicer-style-such-as-light-1-for-quick-v…
agent-aspose-cells-examples May 20, 2026
91b2dc0
Add example: modify-the-slicer-font-family-size-and-color-to-enhance-…
agent-aspose-cells-examples May 20, 2026
9d3b243
Add example: hide-the-slicer-header-row-to-create-a-compact-filtering…
agent-aspose-cells-examples May 20, 2026
020c058
Add example: set-the-slicer-item-sorting-order-to-descending-based-on…
agent-aspose-cells-examples May 20, 2026
997fce4
Add example: configure-the-slicer-to-display-items-with-no-data-by-to…
agent-aspose-cells-examples May 20, 2026
0f3bb85
Add example: arrange-slicer-items-in-multiple-columns-by-setting-the-…
agent-aspose-cells-examples May 20, 2026
dc946b0
Add example: change-the-slicer-layout-direction-to-righttoleft-for-la…
agent-aspose-cells-examples May 20, 2026
07546af
Add example: add-a-slicer-to-a-worksheet-that-contains-a-chart-to-fil…
agent-aspose-cells-examples May 20, 2026
6eef818
Add example: clone-an-existing-slicer-and-place-the-copy-on-another-w…
agent-aspose-cells-examples May 20, 2026
bf568e0
Add example: delete-a-slicer-by-name-from-the-workbook-to-clean-up-un…
agent-aspose-cells-examples May 20, 2026
41fd912
Add example: retrieve-the-collection-of-slicers-from-a-worksheet-and-…
agent-aspose-cells-examples May 20, 2026
52ea024
Add example: programmatically-select-specific-slicer-items-based-on-a…
agent-aspose-cells-examples May 20, 2026
e2f16d7
Add example: clear-all-selected-items-in-a-slicer-to-reset-the-filter…
agent-aspose-cells-examples May 20, 2026
9623600
Add example: lock-a-slicer-to-prevent-end-users-from-modifying-its-co…
agent-aspose-cells-examples May 20, 2026
a9adc19
Add example: set-the-slicer-to-be-printable-so-it-appears-when-the-wo…
agent-aspose-cells-examples May 20, 2026
d2dcf96
Add example: export-the-slicer-as-an-image-and-embed-it-in-a-pdf-repo…
agent-aspose-cells-examples May 20, 2026
417714a
Add example: save-the-workbook-containing-slicers-to-macroenabled-exc…
agent-aspose-cells-examples May 20, 2026
4bedb50
Add example: batch-create-slicers-for-each-pivot-table-in-a-workbook-…
agent-aspose-cells-examples May 20, 2026
26a5e58
Add example: update-slicer-properties-across-all-worksheets-in-a-work…
agent-aspose-cells-examples May 20, 2026
7a8b2dc
Add example: synchronize-two-slicers-so-that-selecting-an-item-in-one…
agent-aspose-cells-examples May 20, 2026
2129ea2
Add example: load-an-xlsx-workbook-remove-a-named-slicer-and-save-the…
agent-aspose-cells-examples May 20, 2026
e0523e8
Add example: iterate-all-worksheets-delete-every-slicer-and-export-th…
agent-aspose-cells-examples May 20, 2026
2a2696f
Add example: identify-slicers-starting-with-region-remove-them-and-sa…
agent-aspose-cells-examples May 20, 2026
93ed120
Add example: retrieve-a-slicer-programmatically-select-multiple-items…
agent-aspose-cells-examples May 20, 2026
5df8853
Add example: unselect-all-items-in-a-slicer-call-refresh-and-export-t…
agent-aspose-cells-examples May 20, 2026
171dc7a
Add example: load-a-workbook-from-a-memory-stream-update-slicer-selec…
agent-aspose-cells-examples May 20, 2026
4638485
Add example: set-the-worksheet-print-area-to-slicer-bounds-then-rende…
agent-aspose-cells-examples May 20, 2026
7193d32
Add example: after-updating-slicer-items-verify-the-associated-pivot-…
agent-aspose-cells-examples May 20, 2026
eed3c08
Add example: create-a-batch-process-that-removes-a-named-slicer-from-…
agent-aspose-cells-examples May 20, 2026
0645ee9
Add example: use-slicercacheitems-to-select-items-based-on-external-c…
agent-aspose-cells-examples May 20, 2026
8871565
Add example: export-a-workbook-containing-slicers-to-pdf-ensuring-all…
agent-aspose-cells-examples May 20, 2026
fda2c55
Add example: compare-slicer-selection-states-before-and-after-calling…
agent-aspose-cells-examples May 20, 2026
3b6ffc6
Add example: use-worksheetslicersremoveall-to-clear-every-slicer-from…
agent-aspose-cells-examples May 20, 2026
c0eba14
Add example: before-exporting-to-pdf-set-pdf-conversion-options-to-em…
agent-aspose-cells-examples May 20, 2026
cbaadf1
Add example: iterate-over-slicercacheitems-to-deselect-items-matching…
agent-aspose-cells-examples May 20, 2026
d0d803d
Add example: save-the-workbook-after-each-slicer-modification-to-crea…
agent-aspose-cells-examples May 20, 2026
81fd4f0
Add example: list-all-slicer-names-on-a-worksheet-and-write-them-to-a…
agent-aspose-cells-examples May 20, 2026
11c7967
Add example: load-workbooks-in-parallel-threads-remove-a-designated-s…
agent-aspose-cells-examples May 20, 2026
7e939cf
Add example: iterate-each-slicer-log-its-selected-items-then-deselect…
agent-aspose-cells-examples May 20, 2026
ab1de3c
Add example: use-a-configuration-flag-to-decide-whether-to-keep-slice…
agent-aspose-cells-examples May 20, 2026
fedecd5
Add example: generate-a-pdf-report-that-includes-only-the-slicer-regi…
agent-aspose-cells-examples May 20, 2026
ca051ee
Add example: write-a-unit-test-verifying-that-slicerrefresh-updates-t…
agent-aspose-cells-examples May 20, 2026
12ca744
Add example: save-the-workbook-with-pdf-options-to-embed-the-slicers-…
agent-aspose-cells-examples May 20, 2026
1361d0a
Add example: after-adding-new-items-to-a-slicers-cache-call-refresh-a…
agent-aspose-cells-examples May 20, 2026
a1630e8
Add example: remove-slicers-from-all-worksheets-in-a-workbook-and-sav…
agent-aspose-cells-examples May 20, 2026
476d082
Add example: create-a-function-returning-true-if-a-slicer-contains-an…
agent-aspose-cells-examples May 20, 2026
8dcc50e
Add example: process-a-list-of-slicer-names-removing-each-one-and-log…
agent-aspose-cells-examples May 20, 2026
9b1e31b
Add example: load-multiple-workbooks-remove-all-slicers-and-archive-t…
agent-aspose-cells-examples May 20, 2026
b2ed3c2
Add example: before-saving-automatically-select-the-first-item-if-a-s…
agent-aspose-cells-examples May 20, 2026
f4defe2
Add example: use-the-workbooks-calculate-method-after-slicer-refresh-…
agent-aspose-cells-examples May 20, 2026
520d35a
Add example: load-an-xlsx-workbook-create-a-slicer-for-a-table-column…
agent-aspose-cells-examples May 20, 2026
4c9e5c4
Add example: load-a-workbook-create-slicers-for-multiple-table-column…
agent-aspose-cells-examples May 20, 2026
8ce192b
Add example: create-a-slicer-linked-to-a-table-column-then-set-its-pl…
agent-aspose-cells-examples May 20, 2026
176177f
Add example: move-the-slicer-to-cell-d5-and-align-it-with-existing-ch…
agent-aspose-cells-examples May 20, 2026
252cf7a
Add example: adjust-slicer-row-height-to-30-points-after-linking-it-t…
agent-aspose-cells-examples May 20, 2026
8c725e5
Add example: set-slicer-row-height-dynamically-based-on-the-number-of…
agent-aspose-cells-examples May 20, 2026
cfbeeb3
Add example: set-slicer-width-to-150-pixels-and-verify-its-appearance…
agent-aspose-cells-examples May 20, 2026
ec88210
Add example: batch-process-multiple-workbooks-adding-slicers-to-each-…
agent-aspose-cells-examples May 20, 2026
a4d9ec7
Add example: change-the-slicer-title-to-region-filter-and-update-the-…
agent-aspose-cells-examples May 20, 2026
9983f5f
Add example: apply-the-slicerstylelight1-formatting-style-to-the-slic…
agent-aspose-cells-examples May 20, 2026
f69529f
Add example: update-slicer-style-based-on-datadriven-criteria-using-t…
agent-aspose-cells-examples May 20, 2026
5812a73
Add example: mark-the-slicer-as-nonprintable-and-ensure-it-does-not-a…
agent-aspose-cells-examples May 20, 2026
0d5962e
Add example: iterate-through-all-slicers-in-the-workbook-and-set-each…
agent-aspose-cells-examples May 20, 2026
1cf7207
Add example: validate-that-the-slicer-printable-flag-is-true-before-e…
agent-aspose-cells-examples May 20, 2026
2bb7973
Add example: add-a-pivot-table-connection-to-the-slicer-for-dynamic-d…
agent-aspose-cells-examples May 20, 2026
5028732
Add example: remove-an-existing-pivot-connection-from-the-slicer-to-s…
agent-aspose-cells-examples May 20, 2026
dc0b4f1
Add example: programmatically-retrieve-slicer-properties-log-them-and…
agent-aspose-cells-examples May 20, 2026
a791bb9
Add example: create-a-slicer-and-retrieve-its-identifier-for-use-in-s…
agent-aspose-cells-examples May 20, 2026
afc2d94
Add example: create-a-slicer-then-copy-its-properties-to-a-new-slicer…
agent-aspose-cells-examples May 20, 2026
50cccfc
Add example: set-slicer-placement-and-ensure-it-remains-unchanged-aft…
agent-aspose-cells-examples May 20, 2026
ecaf9d7
Add example: validate-that-slicer-placement-coordinates-remain-consis…
agent-aspose-cells-examples May 20, 2026
8f56806
Add example: export-the-workbook-containing-slicers-to-pdf-and-compar…
agent-aspose-cells-examples May 20, 2026
ad36a2e
Add example: render-the-workbook-to-pdf-while-preserving-slicer-visua…
agent-aspose-cells-examples May 20, 2026
6edc1fb
Add example: export-the-workbook-to-pdf-with-high-resolution-to-ensur…
agent-aspose-cells-examples May 20, 2026
46fcb18
Add example: convert-the-workbook-with-slicers-to-pdf-while-preservin…
agent-aspose-cells-examples May 20, 2026
e834eab
Add example: implement-error-handling-when-adding-a-slicer-to-a-nonex…
agent-aspose-cells-examples May 20, 2026
96b3c5b
Add example: save-the-workbook-with-slicers-and-compare-file-sizes-wi…
agent-aspose-cells-examples May 20, 2026
146e00a
Add example: generate-a-report-listing-each-slicers-title-size-and-li…
agent-aspose-cells-examples May 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
410 changes: 410 additions & 0 deletions index.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Aspose.Cells;
using Aspose.Cells.Pivot;
using Aspose.Cells.Slicers;

class Program
{
static void Main()
{
// Create a new workbook and get the first worksheet
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

// Populate sample data for the pivot table
cells["A1"].Value = "Category";
cells["B1"].Value = "Product";
cells["C1"].Value = "Sales";

cells["A2"].Value = "Electronics";
cells["B2"].Value = "Laptop";
cells["C2"].Value = 1200;

cells["A3"].Value = "Electronics";
cells["B3"].Value = "Phone";
cells["C3"].Value = 800;

cells["A4"].Value = "Furniture";
cells["B4"].Value = "Chair";
cells["C4"].Value = 150;

// Add a pivot table based on the data range
PivotTableCollection pivotTables = sheet.PivotTables;
int pivotIndex = pivotTables.Add("A1:C4", "E1", "SalesPivot");
PivotTable pivot = pivotTables[pivotIndex];
pivot.AddFieldToArea(PivotFieldType.Row, "Category");
pivot.AddFieldToArea(PivotFieldType.Row, "Product");
pivot.AddFieldToArea(PivotFieldType.Data, "Sales");
pivot.RefreshData();
pivot.CalculateData();

// Add a slicer for the "Category" field (placed at cell F1 -> row 0, column 5)
int slicerIndex = sheet.Slicers.Add(pivot, 0, 5, "Category");
Slicer slicer = sheet.Slicers[slicerIndex];

// Connect the slicer to the pivot table for dynamic filtering
slicer.AddPivotConnection(pivot);

// Save the workbook
workbook.Save("PivotSlicerConnection.xlsx");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using Aspose.Cells;
using Aspose.Cells.Pivot;
using Aspose.Cells.Charts;
using Aspose.Cells.Slicers;

namespace AsposeCellsSlicerChartDemo
{
class Program
{
static void Main()
{
try
{
// Create a new workbook and get the first worksheet
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

// -------------------------------------------------
// 1. Populate sample data (Fruit, Sales)
// -------------------------------------------------
cells["A1"].PutValue("Fruit");
cells["B1"].PutValue("Sales");
cells["A2"].PutValue("Apple");
cells["B2"].PutValue(120);
cells["A3"].PutValue("Orange");
cells["B3"].PutValue(150);
cells["A4"].PutValue("Banana");
cells["B4"].PutValue(90);
cells["A5"].PutValue("Grape");
cells["B5"].PutValue(60);

// -------------------------------------------------
// 2. Create a PivotTable based on the data
// -------------------------------------------------
// Place the pivot table starting at cell D1
int pivotIdx = sheet.PivotTables.Add("A1:B5", "D1", "FruitPivot");
PivotTable pivot = sheet.PivotTables[pivotIdx];

// Row field: Fruit, Data field: Sales (Sum)
pivot.AddFieldToArea(PivotFieldType.Row, "Fruit");
pivot.AddFieldToArea(PivotFieldType.Data, "Sales");

// Refresh to calculate the pivot data
pivot.RefreshData();
pivot.CalculateData();

// -------------------------------------------------
// 3. Add a chart that is linked to the PivotTable
// -------------------------------------------------
// The chart will be placed at rows 12‑22, columns 0‑7
int chartIdx = sheet.Charts.Add(ChartType.Column, 12, 0, 22, 7);
Chart chart = sheet.Charts[chartIdx];
chart.Title.Text = "Sales by Fruit (Pivot)";

// Use a static address that covers the pivot table data area.
// After the pivot is calculated, the data starts at D2 and ends at E5.
chart.NSeries.Add("D2:E5", true);
chart.NSeries[0].Name = "Sales";

// -------------------------------------------------
// 4. Add a slicer linked to the PivotTable's "Fruit" field
// -------------------------------------------------
// Place the slicer at cell G1 (row 0, column 6)
int slicerIdx = sheet.Slicers.Add(pivot, 0, 6, "Fruit");
Slicer slicer = sheet.Slicers[slicerIdx];
slicer.Caption = "Fruit Filter";
slicer.StyleType = SlicerStyleType.SlicerStyleLight2;

// -------------------------------------------------
// 5. Save the workbook
// -------------------------------------------------
workbook.Save("SlicerChartDemo.xlsx", SaveFormat.Xlsx);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using Aspose.Cells;
using Aspose.Cells.Slicers;
using Aspose.Cells.Tables;

namespace AsposeCellsSlicerExample
{
public class AdjustSlicerRowHeight
{
public static void Run()
{
try
{
// Create a new workbook
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

// Populate sample data for the table
sheet.Cells["A1"].PutValue("Product");
sheet.Cells["B1"].PutValue("Category");
sheet.Cells["A2"].PutValue("Apple");
sheet.Cells["B2"].PutValue("Fruit");
sheet.Cells["A3"].PutValue("Carrot");
sheet.Cells["B3"].PutValue("Vegetable");
sheet.Cells["A4"].PutValue("Banana");
sheet.Cells["B4"].PutValue("Fruit");

// Add a ListObject (table) covering the data range
int tableIndex = sheet.ListObjects.Add("A1", "B4", true);
ListObject table = sheet.ListObjects[tableIndex];
table.TableStyleType = TableStyleType.TableStyleMedium2;

// Add a slicer linked to the second column (Category) of the table
int slicerRow = 6; // zero‑based index (row 7)
int slicerColumn = 0; // column A
int slicerIndex = sheet.Slicers.Add(table, table.ListColumns[1], slicerRow, slicerColumn);
Slicer slicer = sheet.Slicers[slicerIndex];

// Adjust the slicer row height to 30 points
slicer.RowHeight = 30;

// Save the workbook
string outputPath = "SlicerRowHeightAdjusted.xlsx";
workbook.Save(outputPath);
Console.WriteLine($"Workbook saved to {outputPath}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}

// Application entry point
public class Program
{
public static void Main(string[] args)
{
AdjustSlicerRowHeight.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using Aspose.Cells;
using Aspose.Cells.Pivot;
using Aspose.Cells.Slicers;

namespace AsposeCellsExamples
{
public class SlicerRefreshDemo
{
public static void Run()
{
try
{
// Create a new workbook and get the first worksheet (data sheet)
Workbook workbook = new Workbook();
Worksheet dataSheet = workbook.Worksheets[0];
Cells cells = dataSheet.Cells;

// Populate initial source data (Product column and Sales column)
cells["A1"].PutValue("Product");
cells["B1"].PutValue("Sales");
cells["A2"].PutValue("Apple");
cells["B2"].PutValue(100);
cells["A3"].PutValue("Banana");
cells["B3"].PutValue(150);
cells["A4"].PutValue("Cherry");
cells["B4"].PutValue(200);

// Add a worksheet for the pivot table
Worksheet pivotSheet = workbook.Worksheets.Add("Pivot");

// Create the pivot table using the source range A1:B4
int pivotIdx = pivotSheet.PivotTables.Add("A1:B4", "D3", "ProductPivot");
PivotTable pivotTable = pivotSheet.PivotTables[pivotIdx];

// Set row field to Product and data field to Sales
pivotTable.AddFieldToArea(PivotFieldType.Row, 0);
pivotTable.AddFieldToArea(PivotFieldType.Data, 1);
pivotTable.CalculateData();

// Add a slicer for the "Product" field on the pivot sheet
int slicerIdx = pivotSheet.Slicers.Add(pivotTable, "F3", "Product");
Slicer slicer = pivotSheet.Slicers[slicerIdx];

// Record the initial number of items in the slicer cache (should be 3)
int initialItemCount = slicer.SlicerCache.SlicerCacheItems.Count;
Console.WriteLine("Initial slicer items count: " + initialItemCount);

// ----- Add new items to the source data (which the slicer is based on) -----
// Append new rows below the existing data
cells["A5"].PutValue("Date");
cells["B5"].PutValue(120);
cells["A6"].PutValue("Elderberry");
cells["B6"].PutValue(80);

// Refresh the slicer – this also refreshes the associated pivot table
slicer.Refresh();

// Recalculate pivot data to reflect any changes
pivotTable.CalculateData();

// Verify that the slicer cache now contains the newly added items
int updatedItemCount = slicer.SlicerCache.SlicerCacheItems.Count;
Console.WriteLine("Updated slicer items count: " + updatedItemCount);

// Simple confirmation that the pivot table reflects the new items
int pivotRowItemCount = pivotTable.RowFields[0].PivotItems.Count;
Console.WriteLine("Pivot row items count: " + pivotRowItemCount);

// Save the workbook
workbook.Save("SlicerRefreshDemo.xlsx");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}

// Entry point for the application
public class Program
{
public static void Main(string[] args)
{
SlicerRefreshDemo.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.IO;
using Aspose.Cells;
using Aspose.Cells.Pivot;
using Aspose.Cells.Slicers;

namespace AsposeCellsSlicerPivotDemo
{
public class Program
{
public static void Main()
{
try
{
// Create a new workbook and get the first worksheet
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;

// Populate source data (Fruit | Sales)
cells["A1"].PutValue("Fruit");
cells["B1"].PutValue("Sales");
cells["A2"].PutValue("Apple");
cells["B2"].PutValue(120);
cells["A3"].PutValue("Banana");
cells["B3"].PutValue(80);
cells["A4"].PutValue("Apple");
cells["B4"].PutValue(150);
cells["A5"].PutValue("Orange");
cells["B5"].PutValue(200);

// Add a pivot table based on the source data
int pivotIdx = sheet.PivotTables.Add("A1:B5", "D3", "FruitPivot");
PivotTable pivot = sheet.PivotTables[pivotIdx];
pivot.AddFieldToArea(PivotFieldType.Row, "Fruit"); // Row field
pivot.AddFieldToArea(PivotFieldType.Data, "Sales"); // Data field (Sum)

// Refresh data and calculate initial results
pivot.RefreshData();
pivot.CalculateData();

// Add a slicer linked to the pivot table for the "Fruit" field
int slicerIdx = sheet.Slicers.Add(pivot, "G3", "Fruit");
Slicer slicer = sheet.Slicers[slicerIdx];

// ---- Update slicer items: select only "Apple" ----
for (int i = 0; i < slicer.SlicerCache.SlicerCacheItems.Count; i++)
{
SlicerCacheItem item = slicer.SlicerCache.SlicerCacheItems[i];
// Select the item if its value is "Apple", otherwise deselect
item.Selected = string.Equals(item.Value, "Apple", StringComparison.OrdinalIgnoreCase);
}

// Refresh the slicer – this also refreshes and recalculates the linked pivot table
slicer.Refresh();

// ---- Verify pivot table reflects the slicer filter ----
// After the slicer filter, the sum for Apple will be in cell E4 (first data row, second column of the pivot)
double appleSum = 0;
try
{
Cell sumCell = sheet.Cells["E4"];
if (sumCell.Value != null && double.TryParse(sumCell.Value.ToString(), out double d))
{
appleSum = d;
}
}
catch (Exception ex)
{
Console.WriteLine($"Failed to read pivot result: {ex.Message}");
}

Console.WriteLine($"Sum of Sales for Apple after slicer filter: {appleSum}");

// Save the workbook (ensure the path is valid)
string outputPath = "SlicerPivotRefreshDemo.xlsx";
try
{
workbook.Save(outputPath);
Console.WriteLine($"Workbook saved to {Path.GetFullPath(outputPath)}");
}
catch (Exception saveEx)
{
Console.WriteLine($"Failed to save workbook: {saveEx.Message}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
}
Loading