Skip to content

Commit 475aa3d

Browse files
committed
update example
1 parent 821ca2a commit 475aa3d

12 files changed

+149
-128
lines changed

CS/SpreadsheetExamples/Form1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void InitData(GroupsOfSpreadsheetExamples examples) {
7676
examples[3].Groups.Add(new SpreadsheetExample("Shared and Array Formulas", FormulaActions.CreateSharedAndArrayFormulasAction));
7777

7878
// Add nodes to the "Formatting" group of examples.
79-
examples[4].Groups.Add(new SpreadsheetExample("Apply a Style", FormattingActions.ApplayStyleAction));
79+
examples[4].Groups.Add(new SpreadsheetExample("Apply a Style", FormattingActions.ApplyStyleAction));
8080
examples[4].Groups.Add(new SpreadsheetExample("Create and Modify a Style", FormattingActions.CreateModifyStyleAction));
8181
examples[4].Groups.Add(new SpreadsheetExample("Individual Cell Formatting", FormattingActions.FormatCellAction));
8282
examples[4].Groups.Add(new SpreadsheetExample("Date Formats", FormattingActions.SetDateFormatsAction));

CS/SpreadsheetExamples/SpreadsheetActions/CellActions.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void ChangeCellValue(Workbook workbook) {
4444
worksheet.Cells["B7"].Value = 'a';
4545
worksheet.Cells["B8"].Value = Int32.MaxValue;
4646

47-
// Fill all cells in the range with 10.
47+
// Fill all cells in the "B10:E10" range with 10.
4848
worksheet.Range["B10:E10"].Value = 10;
4949
#endregion #CellValue
5050
}
@@ -81,8 +81,10 @@ static void SetValueFromText(IWorkbook workbook) {
8181
worksheet.Cells["B8"].SetValueFromText("27-Jul-16 5:43PM", true);
8282
worksheet.Cells["B9"].SetValueFromText("=SQRT(25)");
8383

84-
// Fill all cells in the range with 10.
85-
worksheet.Range["C11:F11"].SetValueFromText("=B1");
84+
// Apply the time display format to the "C11:F11" cell range.
85+
worksheet.Range["C11:F11"].NumberFormat = "m/d/yy h:mm";
86+
// Fill all cells in the "C11:F11" range with the "B1" cell value.
87+
worksheet.Range["C11:F11"].SetValueFromText("=B1", true);
8688
#endregion #SetValueFromText
8789
}
8890
finally {
@@ -103,14 +105,15 @@ static void CreateNamedRange(Workbook workbook) {
103105

104106
// Create a new defined name with the specifed range name and absolute reference.
105107
DefinedName definedName = worksheet.DefinedNames.Add("rangeB17D20", "Sheet1!$B$17:$D$20");
106-
// Create a range using the specified defined name.
108+
// Create a range and use the specified defined name.
107109
CellRange B17D20 = worksheet.Range[definedName.Name];
108110
#endregion #NamedRange
109111
}
110112

111113
static void AddHyperlink(Workbook workbook) {
112114

113115
Worksheet worksheet = workbook.Worksheets[0];
116+
114117
worksheet.Range["A:C"].ColumnWidthInCharacters = 12;
115118

116119
#region #AddHyperlink
@@ -128,6 +131,7 @@ static void AddHyperlink(Workbook workbook) {
128131
static void CopyCellDataAndStyle(Workbook workbook) {
129132
#region #CopyCell
130133
Worksheet worksheet = workbook.Worksheets[0];
134+
131135
worksheet.Columns["A"].WidthInCharacters = 32;
132136
worksheet.Columns["B"].WidthInCharacters = 20;
133137
Style style = workbook.Styles[BuiltInStyleId.Input];
@@ -182,13 +186,12 @@ static void MergeAndSplitCells(Workbook workbook) {
182186
worksheet.Cells["C3"].FillColor = Color.LightSalmon;
183187

184188
#region #MergeCells
185-
// Merge cells contained in the range.
189+
// Merge cells contained in the "A1:C5" range.
186190
worksheet.MergeCells(worksheet.Range["A1:C5"]);
187191
#endregion #MergeCells
188192
}
189193

190194
static void ClearCells(Workbook workbook) {
191-
192195
Worksheet worksheet = workbook.Worksheets[0];
193196

194197
worksheet.Range["A:D"].ColumnWidthInCharacters = 30;

CS/SpreadsheetExamples/SpreadsheetActions/DocumentPropertiesActions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ static void CustomPropertiesValue(IWorkbook workbook)
6969
#endregion #CustomProperties
7070

7171
#region #LinkToContent
72-
//Define a name to the cell to be linked to the custom property
72+
// Define a name to the cell linked to the custom property.
7373
workbook.DefinedNames.Add("checked_by", "E6");
7474

75-
//Connect the custom property with the named cell
75+
// Connect the custom property with the named cell.
7676
workbook.DocumentProperties.Custom.LinkToContent("Checked by", "checked_by");
7777
#endregion #LinkToContent
7878

CS/SpreadsheetExamples/SpreadsheetActions/ExportActions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static void ExportToPdf(Workbook workbook)
1919
workbook.Worksheets[0].Cells["D8"].Value = "This document is exported to the PDF format.";
2020

2121
#region #ExportToPdf
22+
// Export the workbook to PDF.
2223
using (FileStream pdfFileStream = new FileStream("Documents\\Document_PDF.pdf", FileMode.Create))
2324
{
2425
workbook.ExportToPdf(pdfFileStream);

CS/SpreadsheetExamples/SpreadsheetActions/FormattingActions.cs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace SpreadsheetExamples {
99
public static class FormattingActions {
1010
#region Actions
11-
public static Action<Workbook> ApplayStyleAction = ApplayStyle;
11+
public static Action<Workbook> ApplyStyleAction = ApplyStyle;
1212
public static Action<Workbook> CreateModifyStyleAction = CreateModifyStyle;
1313
public static Action<Workbook> FormatCellAction = FormatCell;
1414
public static Action<Workbook> SetDateFormatsAction = SetDateFormats;
@@ -19,17 +19,17 @@ public static class FormattingActions {
1919
public static Action<Workbook> AddCellBordersAction = AddCellBorders;
2020
#endregion
2121

22-
static void ApplayStyle(Workbook workbook) {
22+
static void ApplyStyle(Workbook workbook) {
2323
#region #ApplyCellStyle
2424
Worksheet worksheet = workbook.Worksheets[0];
2525

2626
// Access the built-in "Good" MS Excel style from the Styles collection of the workbook.
2727
Style styleGood = workbook.Styles[BuiltInStyleId.Good];
2828

29-
// Apply the "Good" style to a range of cells.
29+
// Apply the "Good" style to a cell range.
3030
worksheet.Range["A1:C4"].Style = styleGood;
3131

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.
3333
Style customStyle = workbook.Styles["Custom Style"];
3434

3535
// Apply the custom style to the cell.
@@ -45,19 +45,19 @@ static void ApplayStyle(Workbook workbook) {
4545

4646
static void CreateModifyStyle(Workbook workbook) {
4747
#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.
4949
Style myStyle = workbook.Styles.Add("My Style");
5050

5151
// Specify formatting characteristics for the style.
5252
myStyle.BeginUpdate();
5353
try {
54-
// Set the font color to Blue.
54+
// Specify the font color.
5555
myStyle.Font.Color = Color.Blue;
5656

57-
// Set the font size to 12.
57+
// Specify the font size.
5858
myStyle.Font.Size = 12;
5959

60-
// Set the horizontal alignment to Center.
60+
// Specify the horizontal alignment.
6161
myStyle.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
6262

6363
// Set the background.
@@ -104,7 +104,7 @@ static void FormatCell(Workbook workbook) {
104104
worksheet.Range["C3:E6"].Value = "Test";
105105

106106
#region #CellFormatting
107-
// Access the cell to be formatted.
107+
// Access the "B2" cell.
108108
Cell cell = worksheet.Cells["B2"];
109109

110110
// Specify font settings (font name, color, size and style).
@@ -113,19 +113,19 @@ static void FormatCell(Workbook workbook) {
113113
cell.Font.Size = 14;
114114
cell.Font.FontStyle = SpreadsheetFontStyle.Bold;
115115

116-
// Specify cell background color.
116+
// Specify the cell background color.
117117
cell.Fill.BackgroundColor = Color.LightSkyBlue;
118118

119-
// Specify text alignment in the cell.
119+
// Specify text alignment.
120120
cell.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
121121
cell.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
122122
#endregion #CellFormatting
123123

124124
#region #RangeFormatting
125-
// Access the range of cells to be formatted.
125+
// Access the "C3:E6" cell range.
126126
CellRange range = worksheet.Range["C3:E6"];
127127

128-
// Begin updating of the range formatting.
128+
// Start to update the cell range formatting.
129129
Formatting rangeFormatting = range.BeginUpdateFormatting();
130130

131131
// Specify font settings (font name, color, size and style).
@@ -134,14 +134,14 @@ static void FormatCell(Workbook workbook) {
134134
rangeFormatting.Font.Size = 14;
135135
rangeFormatting.Font.FontStyle = SpreadsheetFontStyle.Bold;
136136

137-
// Specify cell background color.
137+
// Specify the cell background color.
138138
rangeFormatting.Fill.BackgroundColor = Color.LightSkyBlue;
139139

140-
// Specify text alignment in cells.
140+
// Specify text alignment.
141141
rangeFormatting.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
142142
rangeFormatting.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
143143

144-
// End updating of the range formatting.
144+
// Finalize to update the cell range formatting.
145145
range.EndUpdateFormatting(rangeFormatting);
146146
#endregion #RangeFormatting
147147
}
@@ -229,7 +229,7 @@ static void ChangeCellColors(Workbook workbook) {
229229
worksheet.Cells["A1"].Font.Color = Color.Red;
230230
worksheet.Cells["A1"].FillColor = Color.Yellow;
231231

232-
// Format a range of cells.
232+
// Format a cell range.
233233
CellRange range = worksheet.Range["C3:D4"];
234234
Formatting rangeFormatting = range.BeginUpdateFormatting();
235235
rangeFormatting.Font.Color = Color.Blue;
@@ -250,15 +250,15 @@ static void SpecifyCellFont(Workbook workbook) {
250250
#region #FontSettings
251251
// Access the Font object.
252252
SpreadsheetFont cellFont = worksheet.Cells["A1"].Font;
253-
// Set the font name.
253+
// Specify the font name.
254254
cellFont.Name = "Times New Roman";
255-
// Set the font size.
255+
// Specify the font size.
256256
cellFont.Size = 14;
257-
// Set the font color.
257+
// Specify the font color.
258258
cellFont.Color = Color.Blue;
259259
// Format text as bold.
260260
cellFont.Bold = true;
261-
// Set font to be underlined.
261+
// Specify the font underline type.
262262
cellFont.UnderlineType = UnderlineType.Double;
263263
#endregion #FontSettings
264264
}
@@ -272,30 +272,36 @@ static void AlignCellContents(Workbook workbook) {
272272
range.RowHeight = 200;
273273

274274
#region #AlignCellContents
275+
// Align the "A1" cell content.
275276
Cell cellA1 = worksheet.Cells["A1"];
276277
cellA1.Value = "Right and top";
277278
cellA1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Right;
278279
cellA1.Alignment.Vertical = SpreadsheetVerticalAlignment.Top;
279280

281+
// Align the "A2" cell content.
280282
Cell cellA2 = worksheet.Cells["A2"];
281283
cellA2.Value = "Center";
282284
cellA2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
283285
cellA2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
284286

287+
// Align the "A3" cell content.
285288
Cell cellA3 = worksheet.Cells["A3"];
286289
cellA3.Value = "Left and bottom, indent";
287290
cellA3.Alignment.Indent = 1;
288291

292+
// Align the "B1" cell content.
289293
Cell cellB1 = worksheet.Cells["B1"];
290294
cellB1.Value = "The Alignment.ShrinkToFit property is applied";
291295
cellB1.Alignment.ShrinkToFit = true;
292296

297+
// Align the "B2" cell content.
293298
Cell cellB2 = worksheet.Cells["B2"];
294299
cellB2.Value = "Rotated Cell Contents";
295300
cellB2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
296301
cellB2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
297302
cellB2.Alignment.RotationAngle = 15;
298303

304+
// Align the "B3" cell content.
299305
Cell cellB3 = worksheet.Cells["B3"];
300306
cellB3.Value = "The Alignment.WrapText property is applied to wrap the text within a cell";
301307
cellB3.Alignment.WrapText = true;
@@ -306,7 +312,7 @@ static void AddCellBorders(Workbook workbook) {
306312
#region #CellBorders
307313
Worksheet worksheet = workbook.Worksheets[0];
308314

309-
// Set each particular border for the cell.
315+
// Specify borders for the "B2" cell.
310316
Cell cellB2 = worksheet.Cells["B2"];
311317
Borders cellB2Borders = cellB2.Borders;
312318
cellB2Borders.LeftBorder.LineStyle = BorderLineStyle.MediumDashDot;
@@ -321,27 +327,27 @@ static void AddCellBorders(Workbook workbook) {
321327
cellB2Borders.DiagonalBorderLineStyle = BorderLineStyle.Thick;
322328
cellB2Borders.DiagonalBorderColor = Color.Red;
323329

324-
// Set diagonal borders for the cell.
330+
// Specify diagonal borders for the "C4" cell.
325331
Cell cellC4 = worksheet.Cells["C4"];
326332
Borders cellC4Borders = cellC4.Borders;
327333
cellC4Borders.SetDiagonalBorders(Color.Orange, BorderLineStyle.Double, DiagonalBorderType.UpAndDown);
328334

329-
// Set all outside borders for the cell in one step.
335+
// Specify outside borders for the "D6" cell.
330336
Cell cellD6 = worksheet.Cells["D6"];
331337
cellD6.Borders.SetOutsideBorders(Color.Gold, BorderLineStyle.Double);
332338
#endregion #CellBorders
333339

334340
#region #CellRangeBorders
335-
// Set all borders for the range of cells in one step.
341+
// Specify all borders for the "B8:F13" cell range.
336342
CellRange range1 = worksheet.Range["B8:F13"];
337343
range1.Borders.SetAllBorders(Color.Green, BorderLineStyle.Double);
338344

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.
340346
CellRange range2 = worksheet.Range["C15:F18"];
341347
range2.SetInsideBorders(Color.SkyBlue, BorderLineStyle.MediumDashed);
342348
range2.Borders.SetOutsideBorders(Color.DeepSkyBlue, BorderLineStyle.Medium);
343349

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.
345351
CellRange range3 = worksheet.Range["D21:F23"];
346352
Formatting range3Formatting = range3.BeginUpdateFormatting();
347353
Borders range3Borders = range3Formatting.Borders;
@@ -351,7 +357,7 @@ static void AddCellBorders(Workbook workbook) {
351357
range3Borders.InsideVerticalBorders.Color = Color.Blue;
352358
range3.EndUpdateFormatting(range3Formatting);
353359

354-
// Set each particular border for the range of cell.
360+
// Specify borders for the "E25:F26" cell range.
355361
CellRange range4 = worksheet.Range["E25:F26"];
356362
Formatting range4Formatting = range4.BeginUpdateFormatting();
357363
Borders range4Borders = range4Formatting.Borders;

0 commit comments

Comments
 (0)