ExcelCell Formula

GemBox.Spreadsheet can read and write formulas, but the level of support depends on the Excel file format:

  • In XLS, all common and some advanced formulas are supported.
  • In XLSX, all formulas are supported. You only need to avoid array formulas in template files.
  • In ODS, all formulas are supported. However, OpenOffice formulas don't have the same syntax as Excel formulas.

Formulas can't be exported to CSV, HTML, PDF or XPS file formats.

Also note that formula values are automatically calculated when a file is opened in Excel.

Screenshot

ExcelCell Formula Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using GemBox.Spreadsheet;
2using System;
3using System.IO;
4
5class Sample
6{
7    [STAThread]
8    static void Main(string[] args)
9    {
10        // If using Professional version, put your serial key below.
11        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
12
13        ExcelFile ef = new ExcelFile();
14        ExcelWorksheet ws = ef.Worksheets.Add("Formula");
15
16        int rowIndex = 0;
17
18        ws.Columns[0].Width = 35 * 256;
19        ws.Columns[1].Width = 15 * 256;
20        ws.Columns[2].Width = 15 * 256;
21
22        ws.Cells[rowIndex++, 0].Value = "Examples of typical formulas usage:";
23
24        ws.Cells[++rowIndex, 0].Value = "Some data:";
25        ws.Cells[rowIndex, 1].SetValue(3);
26        ws.Cells[rowIndex, 2].SetValue(4.1);
27        ws.Cells[++rowIndex, 1].SetValue(5.2);
28        ws.Cells[rowIndex, 2].SetValue(6);
29        ws.Cells[++rowIndex, 1].SetValue(7);
30        ws.Cells[rowIndex++, 2].SetValue(8.3);
31
32        // Named ranges.
33        string namedRange = "Range1";
34        ws.NamedRanges.Add(namedRange, ws.Cells.GetSubrange("B3", "C4"));
35
36        // Floats without first digit.
37        ws.Cells[++rowIndex, 0].Value = "Float number without first digit:";
38        ws.Cells[rowIndex, 1].Formula = "=.5/23+.1-2";
39
40        // Function using named range.
41        ws.Cells[++rowIndex, 0].Value = "Named range:";
42        ws.Cells[rowIndex, 1].Formula = "=SUM(" + namedRange + ")";
43
44        // Function's miss argument.
45        ws.Cells[++rowIndex, 0].Value = "Function's miss arguments:";
46        ws.Cells[rowIndex, 1].Formula = "=Count(1,  ,  ,,,2, 23,,,,,, 34,,,54,,,,  ,)";
47
48        // Functions are case-insensitive.
49        ws.Cells[++rowIndex, 0].Value = "Functions are case-insensitive:";
50        ws.Cells[rowIndex, 1].Formula = "=cOs( 1 )";
51
52        // Functions.
53        ws.Cells[++rowIndex, 0].Value = "Supported functions:";
54
55        string nextFunction;
56        ws.Cells[++rowIndex, 0].Value = "Results";
57        ws.Cells[rowIndex++, 1].Value = "Formulas";
58
59        nextFunction = "=NOW()+123";
60        ws.Cells[rowIndex, 0].Formula = nextFunction;
61        ws.Cells[rowIndex++, 1].Value = nextFunction;
62
63        nextFunction = "=SECOND(12)/23";
64        ws.Cells[rowIndex, 0].Formula = nextFunction;
65        ws.Cells[rowIndex++, 1].Value = nextFunction;
66
67        nextFunction = "=MINUTE(24)-1343/35";
68        ws.Cells[rowIndex, 0].Formula = nextFunction;
69        ws.Cells[rowIndex++, 1].Value = nextFunction;
70
71        nextFunction = "=(HOUR(56)-23/35)";
72        ws.Cells[rowIndex, 0].Formula = nextFunction;
73        ws.Cells[rowIndex++, 1].Value = nextFunction;
74
75        nextFunction = "=WEEKDAY(5)";
76        ws.Cells[rowIndex, 0].Formula = nextFunction;
77        ws.Cells[rowIndex++, 1].Value = nextFunction;
78
79        nextFunction = "=YEAR(23)-WEEKDAY(5)";
80        ws.Cells[rowIndex, 0].Formula = nextFunction;
81        ws.Cells[rowIndex++, 1].Value = nextFunction;
82
83        nextFunction = "=MONTH(3)-2342/235345";
84        ws.Cells[rowIndex, 0].Formula = nextFunction;
85        ws.Cells[rowIndex++, 1].Value = nextFunction;
86
87        nextFunction = "=((DAY(1)))";
88        ws.Cells[rowIndex, 0].Formula = nextFunction;
89        ws.Cells[rowIndex++, 1].Value = nextFunction;
90
91        nextFunction = "=TIME(1,2,3)";
92        ws.Cells[rowIndex, 0].Formula = nextFunction;
93        ws.Cells[rowIndex++, 1].Value = nextFunction;
94
95        nextFunction = "=DATE(1,2,3)";
96        ws.Cells[rowIndex, 0].Formula = nextFunction;
97        ws.Cells[rowIndex++, 1].Value = nextFunction;
98
99        nextFunction = "=RAND()";
100        ws.Cells[rowIndex, 0].Formula = nextFunction;
101        ws.Cells[rowIndex++, 1].Value = nextFunction;
102
103        nextFunction = "=TEXT(\"text\", \"$d\")";
104        ws.Cells[rowIndex, 0].Formula = nextFunction;
105        ws.Cells[rowIndex++, 1].Value = nextFunction;
106
107        nextFunction = "=VAR(1,2)";
108        ws.Cells[rowIndex, 0].Formula = nextFunction;
109        ws.Cells[rowIndex++, 1].Value = nextFunction;
110
111        nextFunction = "=MOD(1,2)";
112        ws.Cells[rowIndex, 0].Formula = nextFunction;
113        ws.Cells[rowIndex++, 1].Value = nextFunction;
114
115        nextFunction = "=NOT(FALSE)";
116        ws.Cells[rowIndex, 0].Formula = nextFunction;
117        ws.Cells[rowIndex++, 1].Value = nextFunction;
118
119        nextFunction = "=OR(FALSE)";
120        ws.Cells[rowIndex, 0].Formula = nextFunction;
121        ws.Cells[rowIndex++, 1].Value = nextFunction;
122
123        nextFunction = "=AND(TRUE)";
124        ws.Cells[rowIndex, 0].Formula = nextFunction;
125        ws.Cells[rowIndex++, 1].Value = nextFunction;
126
127        nextFunction = "=FALSE()";
128        ws.Cells[rowIndex, 0].Formula = nextFunction;
129        ws.Cells[rowIndex++, 1].Value = nextFunction;
130
131        nextFunction = "=TRUE()";
132        ws.Cells[rowIndex, 0].Formula = nextFunction;
133        ws.Cells[rowIndex++, 1].Value = nextFunction;
134
135        nextFunction = "=VALUE(3)";
136        ws.Cells[rowIndex, 0].Formula = nextFunction;
137        ws.Cells[rowIndex++, 1].Value = nextFunction;
138
139        nextFunction = "=LEN(\"hello\")";
140        ws.Cells[rowIndex, 0].Formula = nextFunction;
141        ws.Cells[rowIndex++, 1].Value = nextFunction;
142
143        nextFunction = "=MID(\"hello\",1,1)";
144        ws.Cells[rowIndex, 0].Formula = nextFunction;
145        ws.Cells[rowIndex++, 1].Value = nextFunction;
146
147        nextFunction = "=ROUND(1,2)";
148        ws.Cells[rowIndex, 0].Formula = nextFunction;
149        ws.Cells[rowIndex++, 1].Value = nextFunction;
150
151        nextFunction = "=SIGN(-2)";
152        ws.Cells[rowIndex, 0].Formula = nextFunction;
153        ws.Cells[rowIndex++, 1].Value = nextFunction;
154
155        nextFunction = "=INT(3)";
156        ws.Cells[rowIndex, 0].Formula = nextFunction;
157        ws.Cells[rowIndex++, 1].Value = nextFunction;
158
159        nextFunction = "=ABS(-3)";
160        ws.Cells[rowIndex, 0].Formula = nextFunction;
161        ws.Cells[rowIndex++, 1].Value = nextFunction;
162
163        nextFunction = "=LN(2)";
164        ws.Cells[rowIndex, 0].Formula = nextFunction;
165        ws.Cells[rowIndex++, 1].Value = nextFunction;
166
167        nextFunction = "=EXP(4)";
168        ws.Cells[rowIndex, 0].Formula = nextFunction;
169        ws.Cells[rowIndex++, 1].Value = nextFunction;
170
171        nextFunction = "=SQRT(2)";
172        ws.Cells[rowIndex, 0].Formula = nextFunction;
173        ws.Cells[rowIndex++, 1].Value = nextFunction;
174
175        nextFunction = "=PI()";
176        ws.Cells[rowIndex, 0].Formula = nextFunction;
177        ws.Cells[rowIndex++, 1].Value = nextFunction;
178
179        nextFunction = "=COS(4)";
180        ws.Cells[rowIndex, 0].Formula = nextFunction;
181        ws.Cells[rowIndex++, 1].Value = nextFunction;
182
183        nextFunction = "=SIN(3)";
184        ws.Cells[rowIndex, 0].Formula = nextFunction;
185        ws.Cells[rowIndex++, 1].Value = nextFunction;
186
187        nextFunction = "=MAX(1,2)";
188        ws.Cells[rowIndex, 0].Formula = nextFunction;
189        ws.Cells[rowIndex++, 1].Value = nextFunction;
190
191        nextFunction = "=MIN(1,2)";
192        ws.Cells[rowIndex, 0].Formula = nextFunction;
193        ws.Cells[rowIndex++, 1].Value = nextFunction;
194
195        nextFunction = "=AVERAGE(1,2)";
196        ws.Cells[rowIndex, 0].Formula = nextFunction;
197        ws.Cells[rowIndex++, 1].Value = nextFunction;
198
199        nextFunction = "=SUM(1,3)";
200        ws.Cells[rowIndex, 0].Formula = nextFunction;
201        ws.Cells[rowIndex++, 1].Value = nextFunction;
202
203        nextFunction = "=IF(1,2,3)";
204        ws.Cells[rowIndex, 0].Formula = nextFunction;
205        ws.Cells[rowIndex++, 1].Value = nextFunction;
206
207        nextFunction = "=COUNT(1,2,3)";
208        ws.Cells[rowIndex, 0].Formula = nextFunction;
209        ws.Cells[rowIndex++, 1].Value = nextFunction;
210
211        nextFunction = "=SUBTOTAL(1,B3:C5)";
212        ws.Cells[rowIndex, 0].Formula = nextFunction;
213        ws.Cells[rowIndex++, 1].Value = nextFunction;
214
215        // Paranthless checks.
216        ws.Cells[++rowIndex, 0].Value = "Paranthless:";
217        ws.Cells[rowIndex, 1].Formula = "=((12+2343+34545))";
218
219        // Unary operators.
220        ws.Cells[++rowIndex, 0].Value = "Unary operators:";
221        ws.Cells[rowIndex, 1].Formula = "=B5%";
222        ws.Cells[rowIndex, 2].Formula = "=+++B5";
223
224        // Operand tokens, bool.
225        ws.Cells[++rowIndex, 0].Value = "Bool values:";
226        ws.Cells[rowIndex, 1].Formula = "=TRUE";
227        ws.Cells[rowIndex, 2].Formula = "=FALSE";
228
229        // Operand tokens, int.
230        ws.Cells[++rowIndex, 0].Value = "Integer values:";
231        ws.Cells[rowIndex, 1].Formula = "=1";
232        ws.Cells[rowIndex, 2].Formula = "=20";
233
234        // Operand tokens, num.
235        ws.Cells[++rowIndex, 0].Value = "Float values:";
236        ws.Cells[rowIndex, 1].Formula = "=.4";
237        ws.Cells[rowIndex, 2].Formula = "=2235.5132";
238
239        // Operand tokens, str.
240        ws.Cells[++rowIndex, 0].Value = "String values:";
241        ws.Cells[rowIndex, 1].Formula = "=\"hello world!\"";
242
243        // Operand tokens, error.
244        ws.Cells[++rowIndex, 0].Value = "Error values:";
245        ws.Cells[rowIndex, 1].Formula = "=#NULL!";
246        ws.Cells[rowIndex, 2].Formula = "=#DIV/0!";
247
248        // Binary operators.
249        ws.Cells[++rowIndex, 0].Value = "Binary operators:";
250        ws.Cells[rowIndex, 1].Formula = "=(1)-(2)+(3/2+34)/2+12232-32-4";
251
252        ef.Save("Formula.xls");
253    }
254}
1Imports GemBox.Spreadsheet
2Imports System.IO
3
4Module Samples
5
6    Sub Main()
7
8        ' If using Professional version, put your serial key below.
9        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
10
11        Dim ef As ExcelFile = New ExcelFile
12        Dim ws As ExcelWorksheet = ef.Worksheets.Add("Formula")
13
14        Dim rowIndex As Integer = 0
15
16        ws.Columns(0).Width = 35 * 256
17        ws.Columns(1).Width = 15 * 256
18        ws.Columns(2).Width = 15 * 256
19
20        ws.Cells(rowIndex, 0).Value = "Examples of typical formulas usage:"
21        rowIndex = rowIndex + 2
22
23        ws.Cells(rowIndex, 0).Value = "Some data:"
24        ws.Cells(rowIndex, 1).SetValue(3)
25        ws.Cells(rowIndex, 2).SetValue(4.1)
26        rowIndex = rowIndex + 1
27        ws.Cells(rowIndex, 1).SetValue(5.2)
28        ws.Cells(rowIndex, 2).SetValue(6)
29        rowIndex = rowIndex + 1
30        ws.Cells(rowIndex, 1).SetValue(7)
31        ws.Cells(rowIndex, 2).SetValue(8.3)
32        rowIndex = rowIndex + 1
33
34        ' Named ranges.
35        Dim namedRange As String = "Range1"
36        ws.NamedRanges.Add(namedRange, ws.Cells.GetSubrange("B3", "C4"))
37
38        ' Floats without first digit.
39        rowIndex = rowIndex + 1
40        ws.Cells(rowIndex, 0).Value = "Float number without first digit:"
41        ws.Cells(rowIndex, 1).Formula = "=.5/23+.1-2"
42
43        ' Function using named range.
44        rowIndex = rowIndex + 1
45        ws.Cells(rowIndex, 0).Value = "Named range:"
46        ws.Cells(rowIndex, 1).Formula = "=SUM(" + namedRange + ")"
47
48        ' Function's miss argument.
49        rowIndex = rowIndex + 1
50        ws.Cells(rowIndex, 0).Value = "Function's miss arguments:"
51        ws.Cells(rowIndex, 1).Formula = "=Count(1,  ,  ,,,2, 23,,,,,, 34,,,54,,,,  ,)"
52
53        ' Functions are case-insensitive.
54        rowIndex = rowIndex + 1
55        ws.Cells(rowIndex, 0).Value = "Functions are case-insensitive:"
56        ws.Cells(rowIndex, 1).Formula = "=cOs( 1 )"
57
58        ' Functions.
59        rowIndex = rowIndex + 1
60        ws.Cells(rowIndex, 0).Value = "Supported functions:"
61
62        Dim nextFunction As String
63        rowIndex = rowIndex + 1
64        ws.Cells(rowIndex, 0).Value = "Results"
65        ws.Cells(rowIndex, 1).Value = "Formulas"
66        rowIndex = rowIndex + 1
67
68        nextFunction = "=NOW()+123"
69        ws.Cells(rowIndex, 0).Formula = nextFunction
70        ws.Cells(rowIndex, 1).Value = nextFunction
71        rowIndex = rowIndex + 1
72
73        nextFunction = "=SECOND(12)/23"
74        ws.Cells(rowIndex, 0).Formula = nextFunction
75        ws.Cells(rowIndex, 1).Value = nextFunction
76        rowIndex = rowIndex + 1
77
78        nextFunction = "=MINUTE(24)-1343/35"
79        ws.Cells(rowIndex, 0).Formula = nextFunction
80        ws.Cells(rowIndex, 1).Value = nextFunction
81        rowIndex = rowIndex + 1
82
83        nextFunction = "=(HOUR(56)-23/35)"
84        ws.Cells(rowIndex, 0).Formula = nextFunction
85        ws.Cells(rowIndex, 1).Value = nextFunction
86        rowIndex = rowIndex + 1
87
88        nextFunction = "=WEEKDAY(5)"
89        ws.Cells(rowIndex, 0).Formula = nextFunction
90        ws.Cells(rowIndex, 1).Value = nextFunction
91        rowIndex = rowIndex + 1
92
93        nextFunction = "=YEAR(23)-WEEKDAY(5)"
94        ws.Cells(rowIndex, 0).Formula = nextFunction
95        ws.Cells(rowIndex, 1).Value = nextFunction
96        rowIndex = rowIndex + 1
97
98        nextFunction = "=MONTH(3)-2342/235345"
99        ws.Cells(rowIndex, 0).Formula = nextFunction
100        ws.Cells(rowIndex, 1).Value = nextFunction
101        rowIndex = rowIndex + 1
102
103        nextFunction = "=((DAY(1)))"
104        ws.Cells(rowIndex, 0).Formula = nextFunction
105        ws.Cells(rowIndex, 1).Value = nextFunction
106        rowIndex = rowIndex + 1
107
108        nextFunction = "=TIME(1,2,3)"
109        ws.Cells(rowIndex, 0).Formula = nextFunction
110        ws.Cells(rowIndex, 1).Value = nextFunction
111        rowIndex = rowIndex + 1
112
113        nextFunction = "=DATE(1,2,3)"
114        ws.Cells(rowIndex, 0).Formula = nextFunction
115        ws.Cells(rowIndex, 1).Value = nextFunction
116        rowIndex = rowIndex + 1
117
118        nextFunction = "=RAND()"
119        ws.Cells(rowIndex, 0).Formula = nextFunction
120        ws.Cells(rowIndex, 1).Value = nextFunction
121        rowIndex = rowIndex + 1
122
123        nextFunction = "=TEXT(" + Chr(34) + "text" + Chr(34) + ", " + Chr(34) + "$d" + Chr(34) + ")"
124        ws.Cells(rowIndex, 0).Formula = nextFunction
125        ws.Cells(rowIndex, 1).Value = nextFunction
126        rowIndex = rowIndex + 1
127
128        nextFunction = "=VAR(1,2)"
129        ws.Cells(rowIndex, 0).Formula = nextFunction
130        ws.Cells(rowIndex, 1).Value = nextFunction
131        rowIndex = rowIndex + 1
132
133        nextFunction = "=MOD(1,2)"
134        ws.Cells(rowIndex, 0).Formula = nextFunction
135        ws.Cells(rowIndex, 1).Value = nextFunction
136        rowIndex = rowIndex + 1
137
138        nextFunction = "=NOT(FALSE)"
139        ws.Cells(rowIndex, 0).Formula = nextFunction
140        ws.Cells(rowIndex, 1).Value = nextFunction
141        rowIndex = rowIndex + 1
142
143        nextFunction = "=OR(FALSE)"
144        ws.Cells(rowIndex, 0).Formula = nextFunction
145        ws.Cells(rowIndex, 1).Value = nextFunction
146        rowIndex = rowIndex + 1
147
148        nextFunction = "=AND(TRUE)"
149        ws.Cells(rowIndex, 0).Formula = nextFunction
150        ws.Cells(rowIndex, 1).Value = nextFunction
151        rowIndex = rowIndex + 1
152
153        nextFunction = "=FALSE()"
154        ws.Cells(rowIndex, 0).Formula = nextFunction
155        ws.Cells(rowIndex, 1).Value = nextFunction
156        rowIndex = rowIndex + 1
157
158        nextFunction = "=TRUE()"
159        ws.Cells(rowIndex, 0).Formula = nextFunction
160        ws.Cells(rowIndex, 1).Value = nextFunction
161        rowIndex = rowIndex + 1
162
163        nextFunction = "=VALUE(3)"
164        ws.Cells(rowIndex, 0).Formula = nextFunction
165        ws.Cells(rowIndex, 1).Value = nextFunction
166        rowIndex = rowIndex + 1
167
168        nextFunction = "=LEN(" + Chr(34) + "hello" + Chr(34) + ")"
169        ws.Cells(rowIndex, 0).Formula = nextFunction
170        ws.Cells(rowIndex, 1).Value = nextFunction
171        rowIndex = rowIndex + 1
172
173        nextFunction = "=MID(" + Chr(34) + "hello" + Chr(34) + ",1,1)"
174        ws.Cells(rowIndex, 0).Formula = nextFunction
175        ws.Cells(rowIndex, 1).Value = nextFunction
176        rowIndex = rowIndex + 1
177
178        nextFunction = "=ROUND(1,2)"
179        ws.Cells(rowIndex, 0).Formula = nextFunction
180        ws.Cells(rowIndex, 1).Value = nextFunction
181        rowIndex = rowIndex + 1
182
183        nextFunction = "=SIGN(-2)"
184        ws.Cells(rowIndex, 0).Formula = nextFunction
185        ws.Cells(rowIndex, 1).Value = nextFunction
186        rowIndex = rowIndex + 1
187
188        nextFunction = "=INT(3)"
189        ws.Cells(rowIndex, 0).Formula = nextFunction
190        ws.Cells(rowIndex, 1).Value = nextFunction
191        rowIndex = rowIndex + 1
192
193        nextFunction = "=ABS(-3)"
194        ws.Cells(rowIndex, 0).Formula = nextFunction
195        ws.Cells(rowIndex, 1).Value = nextFunction
196        rowIndex = rowIndex + 1
197
198        nextFunction = "=LN(2)"
199        ws.Cells(rowIndex, 0).Formula = nextFunction
200        ws.Cells(rowIndex, 1).Value = nextFunction
201        rowIndex = rowIndex + 1
202
203        nextFunction = "=EXP(4)"
204        ws.Cells(rowIndex, 0).Formula = nextFunction
205        ws.Cells(rowIndex, 1).Value = nextFunction
206        rowIndex = rowIndex + 1
207
208        nextFunction = "=SQRT(2)"
209        ws.Cells(rowIndex, 0).Formula = nextFunction
210        ws.Cells(rowIndex, 1).Value = nextFunction
211        rowIndex = rowIndex + 1
212
213        nextFunction = "=PI()"
214        ws.Cells(rowIndex, 0).Formula = nextFunction
215        ws.Cells(rowIndex, 1).Value = nextFunction
216        rowIndex = rowIndex + 1
217
218        nextFunction = "=COS(4)"
219        ws.Cells(rowIndex, 0).Formula = nextFunction
220        ws.Cells(rowIndex, 1).Value = nextFunction
221        rowIndex = rowIndex + 1
222
223        nextFunction = "=SIN(3)"
224        ws.Cells(rowIndex, 0).Formula = nextFunction
225        ws.Cells(rowIndex, 1).Value = nextFunction
226        rowIndex = rowIndex + 1
227
228        nextFunction = "=MAX(1,2)"
229        ws.Cells(rowIndex, 0).Formula = nextFunction
230        ws.Cells(rowIndex, 1).Value = nextFunction
231        rowIndex = rowIndex + 1
232
233        nextFunction = "=MIN(1,2)"
234        ws.Cells(rowIndex, 0).Formula = nextFunction
235        ws.Cells(rowIndex, 1).Value = nextFunction
236        rowIndex = rowIndex + 1
237
238        nextFunction = "=AVERAGE(1,2)"
239        ws.Cells(rowIndex, 0).Formula = nextFunction
240        ws.Cells(rowIndex, 1).Value = nextFunction
241        rowIndex = rowIndex + 1
242
243        nextFunction = "=SUM(1,3)"
244        ws.Cells(rowIndex, 0).Formula = nextFunction
245        ws.Cells(rowIndex, 1).Value = nextFunction
246        rowIndex = rowIndex + 1
247
248        nextFunction = "=IF(1,2,3)"
249        ws.Cells(rowIndex, 0).Formula = nextFunction
250        ws.Cells(rowIndex, 1).Value = nextFunction
251        rowIndex = rowIndex + 1
252
253        nextFunction = "=COUNT(1,2,3)"
254        ws.Cells(rowIndex, 0).Formula = nextFunction
255        ws.Cells(rowIndex, 1).Value = nextFunction
256        rowIndex = rowIndex + 1
257
258        nextFunction = "=SUBTOTAL(1,B3:C5)"
259        ws.Cells(rowIndex, 0).Formula = nextFunction
260        ws.Cells(rowIndex, 1).Value = nextFunction
261        rowIndex = rowIndex + 1
262
263        ' Paranthless checks.
264        rowIndex = rowIndex + 1
265        ws.Cells(rowIndex, 0).Value = "Paranthless:"
266        ws.Cells(rowIndex, 1).Formula = "=((12+2343+34545))"
267
268        ' Unary operators.
269        rowIndex = rowIndex + 1
270        ws.Cells(rowIndex, 0).Value = "Unary operators:"
271        ws.Cells(rowIndex, 1).Formula = "=B5%"
272        ws.Cells(rowIndex, 2).Formula = "=+++B5"
273
274        ' Operand tokens, bool.
275        rowIndex = rowIndex + 1
276        ws.Cells(rowIndex, 0).Value = "Bool values:"
277        ws.Cells(rowIndex, 1).Formula = "=TRUE"
278        ws.Cells(rowIndex, 2).Formula = "=FALSE"
279
280        ' Operand tokens, int.
281        rowIndex = rowIndex + 1
282        ws.Cells(rowIndex, 0).Value = "Integer values:"
283        ws.Cells(rowIndex, 1).Formula = "=1"
284        ws.Cells(rowIndex, 2).Formula = "=20"
285
286        ' Operand tokens, num.
287        rowIndex = rowIndex + 1
288        ws.Cells(rowIndex, 0).Value = "Float values:"
289        ws.Cells(rowIndex, 1).Formula = "=.4"
290        ws.Cells(rowIndex, 2).Formula = "=2235.5132"
291
292        ' Operand tokens, str.
293        rowIndex = rowIndex + 1
294        ws.Cells(rowIndex, 0).Value = "String values:"
295        ws.Cells(rowIndex, 1).Formula = "=" + Chr(34) + "hello world!" + Chr(34)
296
297        ' Operand tokens, error.
298        rowIndex = rowIndex + 1
299        ws.Cells(rowIndex, 0).Value = "Error values:"
300        ws.Cells(rowIndex, 1).Formula = "=#NULL!"
301        ws.Cells(rowIndex, 2).Formula = "=#DIV/0!"
302
303        ' Binary operators.
304        rowIndex = rowIndex + 1
305        ws.Cells(rowIndex, 0).Value = "Binary operators:"
306        ws.Cells(rowIndex, 1).Formula = "=(1)-(2)+(3/2+34)/2+12232-32-4"
307
308        ef.Save("Formula.xls")
309
310    End Sub
311
312End Module

Check next sample or find out more about GemBox.Spreadsheet and GemBox Software.