No Matches
<< ignore_errors.c chart.c >>

Example of using the new Excel LAMBDA() function. It demonstrates how to create a lambda function in Excel and also how to assign a name to it so that it can be called as a user defined function. This particular example converts from Fahrenheit to Celsius.

* An example of using the new Excel LAMBDA() function with the libxlsxwriter
* library.
* Copyright 2014-2021, John McNamara,
#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.
"=_xlfn.LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))(32)",
/* Create the lambda function as a defined name and write it as a dynamic formula. */
"=_xlfn.LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))");
worksheet_write_dynamic_formula(worksheet, CELL("A2"), "=ToCelsius(212)", NULL);
return 0;
Struct to represent an Excel workbook.
Definition: workbook.h:293
Struct to represent an Excel worksheet.
Definition: worksheet.h:2108
#define CELL(cell)
Convert an Excel A1 cell string into a (row, col) pair.
Definition: utility.h:46
lxw_error workbook_define_name(lxw_workbook *workbook, const char *name, const char *formula)
Create a defined name in the workbook to use as a variable.
lxw_workbook * workbook_new(const char *filename)
Create a new workbook object.
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)
Add a new worksheet to a workbook.
lxw_error worksheet_write_dynamic_formula(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *formula, lxw_format *format)
Write an Excel 365 dynamic array formula to a worksheet cell.