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
| require 'axlsx'
package = Axlsx::Package.new
sheet = package.workbook.add_worksheet(name: 'lists')
sheet.add_row(['品名', '単価', '数量', '計'])
sheet.add_row(['にんじん', 80, 1, '=B2*C2'])
sheet.add_row(['たまねぎ', 50, 2, '=B3*C3'])
sheet.add_row(['じゃがいも', 40, 2, '=B4*C4'])
sheet.add_row(['牛肉', 200, 1, '=B5*C5'])
sheet.add_row(['カレー粉', 150, 1, '=B6*C6'])
sheet.add_row(['', '', '総計', '=SUM(D2:D6)'])
sheet.add_data_validation("A10", {
:type => :list,
:formula1 => 'A2:A6',
:showDropDown => false,
:showErrorMessage => true,
:errorTitle => '',
:error => 'リストから選んで下さい',
:errorStyle => :stop,
:showInputMessage => true,
:promptTitle => 'カレー具材',
:prompt => 'カレーの具材を選んで下さい。'})
package.serialize('test.xlsx')
|