File: lambda.c

package info (click to toggle)
libxlsxwriter 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,864 kB
  • sloc: ansic: 65,601; python: 2,106; makefile: 693; perl: 229; sh: 224; xml: 168; cpp: 73; javascript: 5
file content (35 lines) | stat: -rw-r--r-- 1,097 bytes parent folder | download | duplicates (2)
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-2025, 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;
}