# -*- coding: utf-8 -*- require 'helper' require 'write_xlsx' require 'stringio' class TestWriteMergeCells < Test::Unit::TestCase def setup @workbook = WriteXLSX.new(StringIO.new) @worksheet = @workbook.add_worksheet('') end def test_write_merge_cells_B3_C3_Foo_format format = Writexlsx::Format.new({}, {}, :xf_index => 1) @worksheet.select @worksheet.merge_range('B3:C3', 'Foo', format) @worksheet.__send__('assemble_xml_file') result = got_to_array(@worksheet.instance_variable_get(:@writer).string) expected = expected_to_array(< 0 EOS ) assert_equal(expected, result) end def test_write_merge_cells_two_range format1 = Writexlsx::Format.new({}, {}, :xf_index => 1) format2 = Writexlsx::Format.new({}, {}, :xf_index => 2) @worksheet.select @worksheet.merge_range('B3:C3', 'Foo', format1) @worksheet.merge_range('A2:D2', nil, format2) @worksheet.__send__('assemble_xml_file') result = got_to_array(@worksheet.instance_variable_get(:@writer).string) expected = expected_to_array(< 0 EOS ) assert_equal(expected, result) end def test_write_merge_range_type format1 = Writexlsx::Format.new({}, {}, :xf_index => 1) format2 = Writexlsx::Format.new({}, {}, :xf_index => 2) format3 = Writexlsx::Format.new({}, {}, :xf_index => 3) @worksheet.set_column('B:C', 12) @worksheet.instance_variable_set(:@date_1904, 0) @worksheet.select @worksheet.merge_range_type('formula', 'B14:C14', '=1+2', format1, 3) @worksheet.merge_range_type('number', 'B2:C2', 123, format1) @worksheet.merge_range_type('string', 'B4:C4', 'foo', format1) @worksheet.merge_range_type('blank', 'B6:C6', format1) # @worksheet.merge_range_type('rich_string', 'B8:C8', 'This is ', format2, 'bold', format1) @worksheet.merge_range_type('date_time', 'B10:C10', '2011-01-01T', format2) # @worksheet.merge_range_type('url', 'B12:C12', 'http://www.perl.com/', format3) @worksheet.__send__('assemble_xml_file') result = got_to_array(@worksheet.instance_variable_get(:@writer).string) expected = expected_to_array(< 123 0 40544 1+2 3 EOS ) assert_equal(expected, result) end =begin def test_write_merge_cells_2_1_2_2_Foo_format format = Writexlsx::Format.new({}, {}, :xf_index => 1) @worksheet.merge_range(2, 1, 2, 2, 'Foo', format) @worksheet.__send__('write_merge_cells') @worksheet.__send__('assemble_xml_file') result = got_to_array(@worksheet.instance_variable_get(:@writer).string) expected = expected_to_array(< 0 EOS ) assert_equal(expected, result) end =end end