forked from SpreadsheetGear/SpreadsheetGearExplorerSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesignerAndExplorerDialogsSample.code.cs
187 lines (159 loc) · 8.38 KB
/
DesignerAndExplorerDialogsSample.code.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
namespace SamplesLibrary.Windows.Samples.WorkbookView
{
public class DesignerAndExplorerDialogsSample : ISpreadsheetGearWindowsSample
{
public void ShowWorkbookDesigner(IWorkbookView workbookView)
{
// NOTE: Must acquire a workbook set lock.
workbookView.GetLock();
try
{
// Get the active workbook set.
SpreadsheetGear.IWorkbookSet workbookSet = workbookView.ActiveWorkbookSet;
// Create the Workbook Designer for the active workbook set.
SpreadsheetGear.Windows.Forms.WorkbookDesigner designer =
new SpreadsheetGear.Windows.Forms.WorkbookDesigner(workbookSet);
// Display the Workbook Designer to the user. GetOwnerWindow() retrieves the parent
// window of the WorkbookView control, which allows the dialog to stay on top even
// when a user clicks back onto the WorkbookView / parent window.
designer.Show(workbookView.GetOwnerWindow());
}
finally
{
// NOTE: Must release the workbook set lock.
workbookView.ReleaseLock();
}
}
public void ShowWorkbookExplorer(IWorkbookView workbookView)
{
// NOTE: Must acquire a workbook set lock.
workbookView.GetLock();
try
{
// Get the active workbook set.
SpreadsheetGear.IWorkbookSet workbookSet = workbookView.ActiveWorkbookSet;
// Create the Workbook Explorer for the active workbook set.
SpreadsheetGear.Windows.Forms.WorkbookExplorer explorer =
new SpreadsheetGear.Windows.Forms.WorkbookExplorer(workbookSet);
// Display the Workbook Explorer to the user. GetOwnerWindow() retrieves the parent
// window of the WorkbookView control, which allows the dialog to stay on top even
// when a user clicks back onto the WorkbookView / parent window.
explorer.Show(workbookView.GetOwnerWindow());
}
finally
{
// NOTE: Must release the workbook set lock.
workbookView.ReleaseLock();
}
}
public void ShowRangeExplorer(IWorkbookView workbookView,
SpreadsheetGear.Windows.Forms.RangeExplorerCategoryFlags categoryFlags)
{
// NOTE: Must acquire a workbook set lock.
workbookView.GetLock();
try
{
// Select a range of cells.
workbookView.ActiveWorksheet.Cells["B2:D3"].Select();
// Get the active workbook set.
SpreadsheetGear.IWorkbookSet workbookSet = workbookView.ActiveWorkbookSet;
// Create the Range Explorer which operates on the current range selection. You can
// limit which categories are displayed in the RangeExplorer by passing in only the
// desired RangeExplorerCategoryFlags, or show all with the "All" flag.
SpreadsheetGear.Windows.Forms.RangeExplorer explorer =
new SpreadsheetGear.Windows.Forms.RangeExplorer(workbookSet, categoryFlags);
// Display the Range Explorer to the user. GetOwnerWindow() retrieves the parent
// window of the WorkbookView control, which allows the dialog to stay on top even
// when a user clicks back onto the WorkbookView / parent window.
explorer.Show(workbookView.GetOwnerWindow());
}
finally
{
// NOTE: Must release the workbook set lock.
workbookView.ReleaseLock();
}
}
public void ShowChartExplorer(IWorkbookView workbookView,
SpreadsheetGear.Windows.Forms.ChartExplorerCategoryFlags categoryFlags)
{
// NOTE: Must acquire a workbook set lock.
workbookView.GetLock();
try
{
// Get a reference to the worksheet's shapes collection.
SpreadsheetGear.IWorksheet worksheet = workbookView.ActiveWorksheet;
SpreadsheetGear.Shapes.IShapes shapes = worksheet.Shapes;
// Delete any existing shapes.
while (shapes.Count != 0)
shapes[0].Delete();
// Load some sample data.
SpreadsheetGear.IRange dataRange = worksheet.Cells["A101:C105"];
dataRange.Formula = "=INT(RAND() * 10 + 5)";
// Add a chart.
SpreadsheetGear.Shapes.IShape shape = shapes.AddChart(10, 10, 320, 150);
SpreadsheetGear.Charts.IChart chart = shape.Chart;
// Set the chart's source data range, plotting series in columns.
chart.SetSourceData(dataRange, SpreadsheetGear.Charts.RowCol.Columns);
// Set the chart type.
chart.ChartType = SpreadsheetGear.Charts.ChartType.ColumnClustered;
// Select the chart shape.
shape.Select(true);
// Get the active workbook set.
SpreadsheetGear.IWorkbookSet workbookSet = workbookView.ActiveWorkbookSet;
// Create the Chart Explorer which operates on the current chart selection. You can
// limit which categories are displayed in the ChartExplorer by passing in only the
// desired ChartExplorerCategoryFlags, or show all with the "All" flag.
SpreadsheetGear.Windows.Forms.ChartExplorer explorer =
new SpreadsheetGear.Windows.Forms.ChartExplorer(workbookSet, categoryFlags);
// Display the Chart Explorer to the user. GetOwnerWindow() retrieves the parent
// window of the WorkbookView control, which allows the dialog to stay on top even
// when a user clicks back onto the WorkbookView / parent window.
explorer.Show(workbookView.GetOwnerWindow());
}
finally
{
// NOTE: Must release the workbook set lock.
workbookView.ReleaseLock();
}
}
public void ShowShapeExplorer(IWorkbookView workbookView,
SpreadsheetGear.Windows.Forms.ShapeExplorerCategoryFlags categoryFlags)
{
// NOTE: Must acquire a workbook set lock.
workbookView.GetLock();
try
{
// Get a reference to the worksheet's shapes collection.
SpreadsheetGear.Shapes.IShapes shapes = workbookView.ActiveWorksheet.Shapes;
// Delete any existing shapes.
while (shapes.Count != 0)
shapes[0].Delete();
// Add a trapezoid.
SpreadsheetGear.Shapes.IShape shape = shapes.AddShape(
SpreadsheetGear.Shapes.AutoShapeType.Trapezoid, 24, 24, 96, 96);
// Select the trapezoid.
shape.Select(true);
// Add a Button
shapes.AddFormControl(SpreadsheetGear.Shapes.FormControlType.ButtonControl, 150, 24, 100, 24);
// Add a TextBox
shapes.AddTextBox(300, 24, 150, 75);
// Get the active workbook set.
SpreadsheetGear.IWorkbookSet workbookSet = workbookView.ActiveWorkbookSet;
// Create the Shape Explorer which operates on the current shape selection. You can limit
// which categories are displayed in the ShapeExplorer by passing in only the desired
// ShapeExplorerCategoryFlags, or show all with the "All" flag.
SpreadsheetGear.Windows.Forms.ShapeExplorer explorer =
new SpreadsheetGear.Windows.Forms.ShapeExplorer(workbookSet, categoryFlags);
// Display the Shape Explorer to the user. GetOwnerWindow() retrieves the parent
// window of the WorkbookView control, which allows the dialog to stay on top even
// when a user clicks back onto the WorkbookView / parent window.
explorer.Show(workbookView.GetOwnerWindow());
}
finally
{
// NOTE: Must release the workbook set lock.
workbookView.ReleaseLock();
}
}
}
}