-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFormulaBasics.cs
35 lines (29 loc) · 1.29 KB
/
FormulaBasics.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
using SpreadCheetah;
namespace SpreadCheetahSamples;
public static class FormulaBasics
{
public static async Task Sample()
{
using (var stream = File.Create("formula-basics.xlsx"))
using (var spreadsheet = await Spreadsheet.CreateNewAsync(stream))
{
await spreadsheet.StartWorksheetAsync("Sheet 1");
// Add numeric values to cells A1, A2, and A3.
await spreadsheet.AddRowAsync([new Cell(10)]);
await spreadsheet.AddRowAsync([new Cell(20)]);
await spreadsheet.AddRowAsync([new Cell(30)]);
// Example of using the SUM formula to add the values above.
// NOTE: Formulas should NOT start with the `=` sign.
var formulaA4 = new Formula("SUM(A1:A3)");
var cellA4 = new Cell(formulaA4);
await spreadsheet.AddRowAsync([cellA4]);
// Formula cells can optionally contain a cached value.
// Formula cells without a cached value will otherwise be calculated when displayed in Excel.
var formulaA5 = new Formula("AVERAGE(A1:A3)");
var cachedValue = 20;
var cellA5 = new Cell(formulaA5, cachedValue);
await spreadsheet.AddRowAsync([cellA5]);
await spreadsheet.FinishAsync();
}
}
}