-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathlambda.rb
executable file
·43 lines (36 loc) · 1.42 KB
/
lambda.rb
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
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#######################################################################
#
# An example of using the new Excel LAMBDA() function with the
# WriteXLSX rubygem. Note, this function is only currently available
# if you are subscribed to the Microsoft Office Beta program.
#
# Copyright 2000-2021, John McNamara, [email protected]
# convert to ruby by Hideo NAKAMURA, [email protected]
#
require 'write_xlsx'
workbook = WriteXLSX.new('lambda.xlsx')
worksheet = workbook.add_worksheet
worksheet.write(
'A1',
'Note: Lambda functions currently only work with the Beta Channel versions of Excel 365'
)
# Write a Lambda function to convert Fahrenheit to Celsius to a cell.
#
# Note that the lambda function parameters must be prefixed with
# "_xlpm.". These prefixes won't show up in Excel.
worksheet.write('A2', '=LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))(32)')
# Create the same formula (without an argument) as a defined name and use that
# to calculate a value.
#
# Note that the formula name is prefixed with "_xlfn." (this is normally
# converted automatically by write_formula but isn't for defined names)
# and note that the lambda function parameters are prefixed with
# "_xlpm.". These prefixes won't show up in Excel.
workbook.define_name(
'ToCelsius',
'=_xlfn.LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))'
)
worksheet.write_dynamic_array_formula('A3', '=ToCelsius(212)')
workbook.close