-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPivotCalculatedItemActions.cs
71 lines (56 loc) · 2.84 KB
/
PivotCalculatedItemActions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using DevExpress.Charts.Model;
using DevExpress.Spreadsheet;
using System;
namespace SpreadsheetDocServerPivotAPI
{
class PivotCalculatedItemActions
{
public static Action<Workbook> AddCalculatedItemAction = AddCalculatedItem;
public static Action<Workbook> RemoveCalculatedItemAction = RemoveCalculatedItem;
public static Action<Workbook> ModifyCalculatedItemAction = ModifyCalculatedItem;
static void AddCalculatedItem(IWorkbook workbook)
{
#region #AddCalculatedItem
Worksheet worksheet = workbook.Worksheets["Report10"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Access the pivot field by its name in the collection.
PivotField field = pivotTable.Fields["State"];
// Add calculated items to the "State" field.
field.CalculatedItems.Add("=Arizona+California+Colorado", "West Total");
field.CalculatedItems.Add("=Illinois+Kansas+Wisconsin", "Midwest Total");
#endregion #AddCalculatedItem
}
static void RemoveCalculatedItem(IWorkbook workbook)
{
#region #RemoveCalculatedItem
Worksheet worksheet = workbook.Worksheets["Report7"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Access the pivot field by its name in the collection.
PivotField field = pivotTable.Fields["Customer"];
// Add a calculated item to the "Customer" field.
field.CalculatedItems.Add("='Big Foods'*110%", "Big Foods Sales Plan");
//Remove the calculated item by its index from the collection.
field.CalculatedItems.RemoveAt(0);
#endregion #RemoveCalculatedItem
}
static void ModifyCalculatedItem(IWorkbook workbook)
{
#region #ModifyCalculatedItem
Worksheet worksheet = workbook.Worksheets["Report7"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Access the pivot field by its name in the collection.
PivotField field = pivotTable.Fields["Customer"];
// Add a calculated item to the "Customer" field.
PivotItem item = field.CalculatedItems.Add("='Big Foods'*110%", "Big Foods Sales Plan");
//Change the formula for the calculated item.
item.Formula = "='Big Foods'*115%";
#endregion #ModifyCalculatedItem
}
}
}