# -*- coding: utf-8 -*- require 'helper' require 'write_xlsx/workbook' require 'write_xlsx/worksheet' require 'stringio' class TestWriteArrayFormula01 < Minitest::Test def setup @workbook = WriteXLSX.new(StringIO.new) @worksheet = @workbook.add_worksheet('') end def test_write_array_formula format = nil @worksheet.select @worksheet.write('B1', [ [ 500, 10 ], [ 300, 15 ] ]) @worksheet.write('B5', [ [ 1, 2, 3 ], [ 20234, 21003, 10000 ] ]) @worksheet.write('A1', '{=SUM(B1:C1*B2:C2)}', format, 9500) @worksheet.write_array_formula('A2:A2', '{=SUM(B1:C1*B2:C2)}', format, 9500) @worksheet.write_array_formula('A5:A7', '{=TREND(C5:C7,B5:B7)}', format, 22196) @worksheet.__send__('assemble_xml_file') result = got_to_array(@worksheet.instance_variable_get(:@writer).string) expected = expected_to_array(< SUM(B1:C1*B2:C2) 9500 500 300 SUM(B1:C1*B2:C2) 9500 10 15 TREND(C5:C7,B5:B7) 22196 1 20234 0 2 21003 0 3 10000 EOS ) assert_equal(expected, result) end end