-
-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathlambda.c
More file actions
35 lines (26 loc) · 1.07 KB
/
Copy pathlambda.c
File metadata and controls
35 lines (26 loc) · 1.07 KB
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
/*
* An example of using the new Excel LAMBDA() function with the libxlsxwriter
* library.
*
* Copyright 2014-2026, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("lambda.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
/* Note that the formula name is prefixed with "_xlfn." and that the
* lambda function parameters are prefixed with "_xlpm.". These prefixes
* won't show up in Excel.
*/
worksheet_write_dynamic_formula(worksheet, CELL("A1"),
"=_xlfn.LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))(32)",
NULL);
/* Create the lambda function as a defined name and write it as a dynamic formula. */
workbook_define_name(workbook,
"ToCelsius",
"=_xlfn.LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))");
worksheet_write_dynamic_formula(worksheet, CELL("A2"), "=ToCelsius(212)", NULL);
workbook_close(workbook);
return 0;
}