8
8
namespace SpreadsheetExamples {
9
9
public static class FormattingActions {
10
10
#region Actions
11
- public static Action < Workbook > ApplayStyleAction = ApplayStyle ;
11
+ public static Action < Workbook > ApplyStyleAction = ApplyStyle ;
12
12
public static Action < Workbook > CreateModifyStyleAction = CreateModifyStyle ;
13
13
public static Action < Workbook > FormatCellAction = FormatCell ;
14
14
public static Action < Workbook > SetDateFormatsAction = SetDateFormats ;
@@ -19,17 +19,17 @@ public static class FormattingActions {
19
19
public static Action < Workbook > AddCellBordersAction = AddCellBorders ;
20
20
#endregion
21
21
22
- static void ApplayStyle ( Workbook workbook ) {
22
+ static void ApplyStyle ( Workbook workbook ) {
23
23
#region #ApplyCellStyle
24
24
Worksheet worksheet = workbook . Worksheets [ 0 ] ;
25
25
26
26
// Access the built-in "Good" MS Excel style from the Styles collection of the workbook.
27
27
Style styleGood = workbook . Styles [ BuiltInStyleId . Good ] ;
28
28
29
- // Apply the "Good" style to a range of cells .
29
+ // Apply the "Good" style to a cell range .
30
30
worksheet . Range [ "A1:C4" ] . Style = styleGood ;
31
31
32
- // Access a custom style that has been previously created in the loaded document by its name.
32
+ // Access a previously created custom style by its name.
33
33
Style customStyle = workbook . Styles [ "Custom Style" ] ;
34
34
35
35
// Apply the custom style to the cell.
@@ -45,19 +45,19 @@ static void ApplayStyle(Workbook workbook) {
45
45
46
46
static void CreateModifyStyle ( Workbook workbook ) {
47
47
#region #CreateNewStyle
48
- // Add a new style under the "My Style" name to the Styles collection of the workbook .
48
+ // Add a new style under the "My Style" name to the workbook's Styles collection.
49
49
Style myStyle = workbook . Styles . Add ( "My Style" ) ;
50
50
51
51
// Specify formatting characteristics for the style.
52
52
myStyle . BeginUpdate ( ) ;
53
53
try {
54
- // Set the font color to Blue .
54
+ // Specify the font color.
55
55
myStyle . Font . Color = Color . Blue ;
56
56
57
- // Set the font size to 12 .
57
+ // Specify the font size.
58
58
myStyle . Font . Size = 12 ;
59
59
60
- // Set the horizontal alignment to Center .
60
+ // Specify the horizontal alignment.
61
61
myStyle . Alignment . Horizontal = SpreadsheetHorizontalAlignment . Center ;
62
62
63
63
// Set the background.
@@ -104,7 +104,7 @@ static void FormatCell(Workbook workbook) {
104
104
worksheet . Range [ "C3:E6" ] . Value = "Test" ;
105
105
106
106
#region #CellFormatting
107
- // Access the cell to be formatted .
107
+ // Access the "B2" cell .
108
108
Cell cell = worksheet . Cells [ "B2" ] ;
109
109
110
110
// Specify font settings (font name, color, size and style).
@@ -113,19 +113,19 @@ static void FormatCell(Workbook workbook) {
113
113
cell . Font . Size = 14 ;
114
114
cell . Font . FontStyle = SpreadsheetFontStyle . Bold ;
115
115
116
- // Specify cell background color.
116
+ // Specify the cell background color.
117
117
cell . Fill . BackgroundColor = Color . LightSkyBlue ;
118
118
119
- // Specify text alignment in the cell .
119
+ // Specify text alignment.
120
120
cell . Alignment . Vertical = SpreadsheetVerticalAlignment . Center ;
121
121
cell . Alignment . Horizontal = SpreadsheetHorizontalAlignment . Center ;
122
122
#endregion #CellFormatting
123
123
124
124
#region #RangeFormatting
125
- // Access the range of cells to be formatted .
125
+ // Access the "C3:E6" cell range .
126
126
CellRange range = worksheet . Range [ "C3:E6" ] ;
127
127
128
- // Begin updating of the range formatting.
128
+ // Start to update the cell range formatting.
129
129
Formatting rangeFormatting = range . BeginUpdateFormatting ( ) ;
130
130
131
131
// Specify font settings (font name, color, size and style).
@@ -134,14 +134,14 @@ static void FormatCell(Workbook workbook) {
134
134
rangeFormatting . Font . Size = 14 ;
135
135
rangeFormatting . Font . FontStyle = SpreadsheetFontStyle . Bold ;
136
136
137
- // Specify cell background color.
137
+ // Specify the cell background color.
138
138
rangeFormatting . Fill . BackgroundColor = Color . LightSkyBlue ;
139
139
140
- // Specify text alignment in cells .
140
+ // Specify text alignment.
141
141
rangeFormatting . Alignment . Vertical = SpreadsheetVerticalAlignment . Center ;
142
142
rangeFormatting . Alignment . Horizontal = SpreadsheetHorizontalAlignment . Center ;
143
143
144
- // End updating of the range formatting.
144
+ // Finalize to update the cell range formatting.
145
145
range . EndUpdateFormatting ( rangeFormatting ) ;
146
146
#endregion #RangeFormatting
147
147
}
@@ -229,7 +229,7 @@ static void ChangeCellColors(Workbook workbook) {
229
229
worksheet . Cells [ "A1" ] . Font . Color = Color . Red ;
230
230
worksheet . Cells [ "A1" ] . FillColor = Color . Yellow ;
231
231
232
- // Format a range of cells .
232
+ // Format a cell range .
233
233
CellRange range = worksheet . Range [ "C3:D4" ] ;
234
234
Formatting rangeFormatting = range . BeginUpdateFormatting ( ) ;
235
235
rangeFormatting . Font . Color = Color . Blue ;
@@ -250,15 +250,15 @@ static void SpecifyCellFont(Workbook workbook) {
250
250
#region #FontSettings
251
251
// Access the Font object.
252
252
SpreadsheetFont cellFont = worksheet . Cells [ "A1" ] . Font ;
253
- // Set the font name.
253
+ // Specify the font name.
254
254
cellFont . Name = "Times New Roman" ;
255
- // Set the font size.
255
+ // Specify the font size.
256
256
cellFont . Size = 14 ;
257
- // Set the font color.
257
+ // Specify the font color.
258
258
cellFont . Color = Color . Blue ;
259
259
// Format text as bold.
260
260
cellFont . Bold = true ;
261
- // Set font to be underlined .
261
+ // Specify the font underline type .
262
262
cellFont . UnderlineType = UnderlineType . Double ;
263
263
#endregion #FontSettings
264
264
}
@@ -272,30 +272,36 @@ static void AlignCellContents(Workbook workbook) {
272
272
range . RowHeight = 200 ;
273
273
274
274
#region #AlignCellContents
275
+ // Align the "A1" cell content.
275
276
Cell cellA1 = worksheet . Cells [ "A1" ] ;
276
277
cellA1 . Value = "Right and top" ;
277
278
cellA1 . Alignment . Horizontal = SpreadsheetHorizontalAlignment . Right ;
278
279
cellA1 . Alignment . Vertical = SpreadsheetVerticalAlignment . Top ;
279
280
281
+ // Align the "A2" cell content.
280
282
Cell cellA2 = worksheet . Cells [ "A2" ] ;
281
283
cellA2 . Value = "Center" ;
282
284
cellA2 . Alignment . Horizontal = SpreadsheetHorizontalAlignment . Center ;
283
285
cellA2 . Alignment . Vertical = SpreadsheetVerticalAlignment . Center ;
284
286
287
+ // Align the "A3" cell content.
285
288
Cell cellA3 = worksheet . Cells [ "A3" ] ;
286
289
cellA3 . Value = "Left and bottom, indent" ;
287
290
cellA3 . Alignment . Indent = 1 ;
288
291
292
+ // Align the "B1" cell content.
289
293
Cell cellB1 = worksheet . Cells [ "B1" ] ;
290
294
cellB1 . Value = "The Alignment.ShrinkToFit property is applied" ;
291
295
cellB1 . Alignment . ShrinkToFit = true ;
292
296
297
+ // Align the "B2" cell content.
293
298
Cell cellB2 = worksheet . Cells [ "B2" ] ;
294
299
cellB2 . Value = "Rotated Cell Contents" ;
295
300
cellB2 . Alignment . Horizontal = SpreadsheetHorizontalAlignment . Center ;
296
301
cellB2 . Alignment . Vertical = SpreadsheetVerticalAlignment . Center ;
297
302
cellB2 . Alignment . RotationAngle = 15 ;
298
303
304
+ // Align the "B3" cell content.
299
305
Cell cellB3 = worksheet . Cells [ "B3" ] ;
300
306
cellB3 . Value = "The Alignment.WrapText property is applied to wrap the text within a cell" ;
301
307
cellB3 . Alignment . WrapText = true ;
@@ -306,7 +312,7 @@ static void AddCellBorders(Workbook workbook) {
306
312
#region #CellBorders
307
313
Worksheet worksheet = workbook . Worksheets [ 0 ] ;
308
314
309
- // Set each particular border for the cell.
315
+ // Specify borders for the "B2" cell.
310
316
Cell cellB2 = worksheet . Cells [ "B2" ] ;
311
317
Borders cellB2Borders = cellB2 . Borders ;
312
318
cellB2Borders . LeftBorder . LineStyle = BorderLineStyle . MediumDashDot ;
@@ -321,27 +327,27 @@ static void AddCellBorders(Workbook workbook) {
321
327
cellB2Borders . DiagonalBorderLineStyle = BorderLineStyle . Thick ;
322
328
cellB2Borders . DiagonalBorderColor = Color . Red ;
323
329
324
- // Set diagonal borders for the cell.
330
+ // Specify diagonal borders for the "C4" cell.
325
331
Cell cellC4 = worksheet . Cells [ "C4" ] ;
326
332
Borders cellC4Borders = cellC4 . Borders ;
327
333
cellC4Borders . SetDiagonalBorders ( Color . Orange , BorderLineStyle . Double , DiagonalBorderType . UpAndDown ) ;
328
334
329
- // Set all outside borders for the cell in one step .
335
+ // Specify outside borders for the "D6" cell .
330
336
Cell cellD6 = worksheet . Cells [ "D6" ] ;
331
337
cellD6 . Borders . SetOutsideBorders ( Color . Gold , BorderLineStyle . Double ) ;
332
338
#endregion #CellBorders
333
339
334
340
#region #CellRangeBorders
335
- // Set all borders for the range of cells in one step .
341
+ // Specify all borders for the "B8:F13" cell range .
336
342
CellRange range1 = worksheet . Range [ "B8:F13" ] ;
337
343
range1 . Borders . SetAllBorders ( Color . Green , BorderLineStyle . Double ) ;
338
344
339
- // Set all inside and outside borders separately for the range of cells .
345
+ // Specify inside and outside borders for the "C15:F18" cell range .
340
346
CellRange range2 = worksheet . Range [ "C15:F18" ] ;
341
347
range2 . SetInsideBorders ( Color . SkyBlue , BorderLineStyle . MediumDashed ) ;
342
348
range2 . Borders . SetOutsideBorders ( Color . DeepSkyBlue , BorderLineStyle . Medium ) ;
343
349
344
- // Set all horizontal and vertical borders separately for the range of cells .
350
+ // Specify horizontal and vertical borders for the "D21:F23" cell range .
345
351
CellRange range3 = worksheet . Range [ "D21:F23" ] ;
346
352
Formatting range3Formatting = range3 . BeginUpdateFormatting ( ) ;
347
353
Borders range3Borders = range3Formatting . Borders ;
@@ -351,7 +357,7 @@ static void AddCellBorders(Workbook workbook) {
351
357
range3Borders . InsideVerticalBorders . Color = Color . Blue ;
352
358
range3 . EndUpdateFormatting ( range3Formatting ) ;
353
359
354
- // Set each particular border for the range of cell.
360
+ // Specify borders for the "E25:F26" cell range .
355
361
CellRange range4 = worksheet . Range [ "E25:F26" ] ;
356
362
Formatting range4Formatting = range4 . BeginUpdateFormatting ( ) ;
357
363
Borders range4Borders = range4Formatting . Borders ;
0 commit comments