-
Notifications
You must be signed in to change notification settings - Fork 5
/
WorksheetActions.cs
131 lines (111 loc) · 5.52 KB
/
WorksheetActions.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
using System;
using System.Drawing;
using DevExpress.Spreadsheet;
namespace SpreadsheetControl_API {
public static class WorksheetActions {
#region Actions
public static Action<IWorkbook> AssignActiveWorksheetAction = AssignActiveWorksheet;
public static Action<IWorkbook> AddWorksheetAction = AddWorksheet;
public static Action<IWorkbook> RemoveWorksheetAction = RemoveWorksheet;
public static Action<IWorkbook> RenameWorksheetAction = RenameWorksheet;
public static Action<IWorkbook> CopyWorksheetWithinWorkbookAction = CopyWorksheetWithinWorkbook;
public static Action<IWorkbook> MoveWorksheetAction = MoveWorksheet;
public static Action<IWorkbook> ShowHideWorksheetAction = ShowHideWorksheet;
public static Action<IWorkbook> ShowHideGridlinesAction = ShowHideGridlines;
public static Action<IWorkbook> ShowHideHeadingsAction = ShowHideHeadings;
public static Action<IWorkbook> ZoomWorksheetAction = ZoomWorksheet;
#endregion
static void AssignActiveWorksheet(IWorkbook workbook) {
#region #ActiveWorksheet
// Set the second worksheet ("Sheet2") as the active worksheet.
workbook.Worksheets.ActiveWorksheet = workbook.Worksheets["Sheet2"];
#endregion #ActiveWorksheet
}
static void AddWorksheet(IWorkbook workbook) {
workbook.BeginUpdate();
try {
#region #AddWorksheet
// Add a new worksheet to the workbook.
// The worksheet will be inserted into the end of the existing collection of worksheets.
// Worksheet name is "SheetN", where N is a number following the largest number used in existing worksheet names of the same type.
workbook.Worksheets.Add();
// Add a new worksheet under the specified name.
workbook.Worksheets.Add().Name = "TestSheet1";
workbook.Worksheets.Add("TestSheet2");
// Add a new worksheet at the specified position in the collection of worksheets.
workbook.Worksheets.Insert(1, "TestSheet3");
workbook.Worksheets.Insert(3);
#endregion #AddWorksheet
}
finally {
workbook.EndUpdate();
}
}
static void RemoveWorksheet(IWorkbook workbook) {
#region #DeleteWorksheet
// Delete the "Sheet2" worksheet from the workbook.
workbook.Worksheets.Remove(workbook.Worksheets["Sheet2"]);
// Delete the first worksheet from the workbook.
workbook.Worksheets.RemoveAt(0);
#endregion #DeleteWorksheet
}
static void RenameWorksheet(IWorkbook workbook) {
#region #RenameWorksheet
// Change the name of the second worksheet.
workbook.Worksheets[1].Name = "Renamed Sheet";
#endregion #RenameWorksheet
}
static void CopyWorksheetWithinWorkbook(IWorkbook workbook) {
workbook.BeginUpdate();
try {
workbook.Worksheets["Sheet1"].Cells.FillColor = Color.LightSteelBlue;
workbook.Worksheets["Sheet1"].Cells["A1"].ColumnWidthInCharacters = 50;
workbook.Worksheets["Sheet1"].Cells["A1"].Value = "Sheet1's Content";
#region #CopyWorksheet
// Add a new worksheet to a workbook.
workbook.Worksheets.Add("Sheet1_Copy");
// Copy all information (content and formatting) to the newly created worksheet
// from the "Sheet1" worksheet.
workbook.Worksheets["Sheet1_Copy"].CopyFrom(workbook.Worksheets["Sheet1"]);
#endregion #CopyWorksheet
}
finally {
workbook.EndUpdate();
}
}
static void MoveWorksheet(IWorkbook workbook) {
#region #MoveWorksheet
// Move the first worksheet to the position of the last worksheet within the workbook.
workbook.Worksheets[0].Move(workbook.Worksheets.Count - 1);
#endregion #MoveWorksheet
}
static void ShowHideWorksheet(IWorkbook workbook) {
#region #ShowHideWorksheet
// Hide the "Sheet2" worksheet and prevent end-users from unhiding it via the user interface.
// To make this worksheet visible again, use the Worksheet.Visible property.
workbook.Worksheets["Sheet2"].VisibilityType = WorksheetVisibilityType.VeryHidden;
// Hide the "Sheet3" worksheet.
// In this state, the worksheet can be unhidden via the user interface.
workbook.Worksheets["Sheet3"].Visible = false;
#endregion #ShowHideWorksheet
}
static void ShowHideGridlines(IWorkbook workbook) {
#region #ShowHideGridlines
// Hide gridlines in the first worksheet.
workbook.Worksheets[0].ActiveView.ShowGridlines = false;
#endregion #ShowHideGridlines
}
static void ShowHideHeadings(IWorkbook workbook) {
#region #ShowHideHeadings
// Hide row and column headings in the first worksheet.
workbook.Worksheets[0].ActiveView.ShowHeadings = false;
#endregion #ShowHideHeadings
}
static void ZoomWorksheet(IWorkbook workbook) {
#region #WorksheetZoom
// Zoom in to the worksheet view.
workbook.Worksheets[0].ActiveView.Zoom = 150;
#endregion #WorksheetZoom
}
}
}