writeexcel 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/README +26 -31
  2. data/examples/a_simple.rb +42 -42
  3. data/examples/{autofilters.rb → autofilter.rb} +264 -266
  4. data/examples/bigfile.rb +29 -0
  5. data/examples/chart_area.rb +120 -0
  6. data/examples/chart_bar.rb +119 -0
  7. data/examples/chart_column.rb +119 -0
  8. data/examples/chart_line.rb +119 -0
  9. data/examples/chart_pie.rb +107 -0
  10. data/examples/chart_scatter.rb +120 -0
  11. data/examples/chart_stock.rb +147 -0
  12. data/examples/copyformat.rb +51 -51
  13. data/examples/data_validate.rb +278 -278
  14. data/examples/date_time.rb +86 -86
  15. data/examples/defined_name.rb +31 -0
  16. data/examples/demo.rb +120 -118
  17. data/examples/diag_border.rb +35 -35
  18. data/examples/formats.rb +489 -489
  19. data/examples/header.rb +136 -136
  20. data/examples/hidden.rb +28 -28
  21. data/examples/hyperlink.rb +42 -42
  22. data/examples/images.rb +52 -52
  23. data/examples/merge1.rb +39 -39
  24. data/examples/merge2.rb +44 -44
  25. data/examples/merge3.rb +65 -65
  26. data/examples/merge4.rb +82 -82
  27. data/examples/merge5.rb +79 -79
  28. data/examples/properties.rb +33 -0
  29. data/examples/properties_jp.rb +32 -0
  30. data/examples/protection.rb +46 -46
  31. data/examples/regions.rb +52 -52
  32. data/examples/repeat.rb +42 -42
  33. data/examples/stats.rb +75 -75
  34. data/examples/stocks.rb +80 -80
  35. data/examples/tab_colors.rb +30 -30
  36. data/examples/write_arrays.rb +82 -0
  37. data/lib/writeexcel.rb +1134 -18
  38. data/lib/writeexcel/biffwriter.rb +273 -260
  39. data/lib/writeexcel/chart.rb +2306 -217
  40. data/lib/writeexcel/charts/area.rb +152 -0
  41. data/lib/writeexcel/charts/bar.rb +177 -0
  42. data/lib/writeexcel/charts/column.rb +156 -0
  43. data/lib/writeexcel/charts/external.rb +61 -0
  44. data/lib/writeexcel/charts/line.rb +152 -0
  45. data/lib/writeexcel/charts/pie.rb +169 -0
  46. data/lib/writeexcel/charts/scatter.rb +192 -0
  47. data/lib/writeexcel/charts/stock.rb +211 -0
  48. data/lib/writeexcel/excelformulaparser.rb +208 -195
  49. data/lib/writeexcel/format.rb +1697 -1108
  50. data/lib/writeexcel/formula.rb +1050 -986
  51. data/lib/writeexcel/olewriter.rb +322 -322
  52. data/lib/writeexcel/properties.rb +251 -250
  53. data/lib/writeexcel/storage_lite.rb +968 -0
  54. data/lib/writeexcel/workbook.rb +3294 -2630
  55. data/lib/writeexcel/worksheet.rb +9012 -6377
  56. data/test/excelfile/Chart1.xls +0 -0
  57. data/test/excelfile/Chart2.xls +0 -0
  58. data/test/excelfile/Chart3.xls +0 -0
  59. data/test/excelfile/Chart4.xls +0 -0
  60. data/test/excelfile/Chart5.xls +0 -0
  61. data/test/perl_output/Chart1.xls.data +0 -0
  62. data/test/perl_output/Chart2.xls.data +0 -0
  63. data/test/perl_output/Chart3.xls.data +0 -0
  64. data/test/perl_output/Chart4.xls.data +0 -0
  65. data/test/perl_output/Chart5.xls.data +0 -0
  66. data/test/perl_output/a_simple.xls +0 -0
  67. data/test/perl_output/autofilter.xls +0 -0
  68. data/test/perl_output/chart_area.xls +0 -0
  69. data/test/perl_output/chart_bar.xls +0 -0
  70. data/test/perl_output/chart_column.xls +0 -0
  71. data/test/perl_output/chart_line.xls +0 -0
  72. data/test/perl_output/data_validate.xls +0 -0
  73. data/test/perl_output/date_time.xls +0 -0
  74. data/test/perl_output/demo.xls +0 -0
  75. data/test/perl_output/demo101.bin +0 -0
  76. data/test/perl_output/demo201.bin +0 -0
  77. data/test/perl_output/demo301.bin +0 -0
  78. data/test/perl_output/demo401.bin +0 -0
  79. data/test/perl_output/demo501.bin +0 -0
  80. data/test/perl_output/diag_border.xls +0 -0
  81. data/test/perl_output/headers.xls +0 -0
  82. data/test/perl_output/hyperlink.xls +0 -0
  83. data/test/perl_output/images.xls +0 -0
  84. data/test/perl_output/merge1.xls +0 -0
  85. data/test/perl_output/merge2.xls +0 -0
  86. data/test/perl_output/merge3.xls +0 -0
  87. data/test/perl_output/merge4.xls +0 -0
  88. data/test/perl_output/merge5.xls +0 -0
  89. data/test/perl_output/protection.xls +0 -0
  90. data/test/perl_output/regions.xls +0 -0
  91. data/test/perl_output/stats.xls +0 -0
  92. data/test/perl_output/stocks.xls +0 -0
  93. data/test/perl_output/tab_colors.xls +0 -0
  94. data/test/perl_output/unicode_cyrillic.xls +0 -0
  95. data/test/perl_output/workbook1.xls +0 -0
  96. data/test/perl_output/workbook2.xls +0 -0
  97. data/test/tc_all.rb +32 -31
  98. data/test/tc_biff.rb +104 -104
  99. data/test/tc_chart.rb +22 -22
  100. data/test/tc_example_match.rb +1944 -1280
  101. data/test/tc_format.rb +1254 -1267
  102. data/test/tc_formula.rb +63 -63
  103. data/test/tc_ole.rb +110 -110
  104. data/test/tc_storage_lite.rb +149 -0
  105. data/test/tc_workbook.rb +140 -115
  106. data/test/tc_worksheet.rb +115 -115
  107. data/test/test_00_IEEE_double.rb +14 -14
  108. data/test/test_01_add_worksheet.rb +12 -12
  109. data/test/test_02_merge_formats.rb +58 -58
  110. data/test/test_04_dimensions.rb +397 -397
  111. data/test/test_05_rows.rb +182 -182
  112. data/test/test_06_extsst.rb +80 -80
  113. data/test/test_11_date_time.rb +484 -484
  114. data/test/test_12_date_only.rb +506 -506
  115. data/test/test_13_date_seconds.rb +486 -486
  116. data/test/test_21_escher.rb +642 -629
  117. data/test/test_22_mso_drawing_group.rb +750 -739
  118. data/test/test_23_note.rb +78 -78
  119. data/test/test_24_txo.rb +80 -80
  120. data/test/test_25_position_object.rb +82 -0
  121. data/test/test_26_autofilter.rb +327 -327
  122. data/test/test_27_autofilter.rb +144 -144
  123. data/test/test_28_autofilter.rb +174 -174
  124. data/test/test_29_process_jpg.rb +681 -131
  125. data/test/test_30_validation_dval.rb +82 -82
  126. data/test/test_31_validation_dv_strings.rb +131 -131
  127. data/test/test_32_validation_dv_formula.rb +211 -211
  128. data/test/test_40_property_types.rb +191 -191
  129. data/test/test_41_properties.rb +238 -238
  130. data/test/test_42_set_properties.rb +442 -419
  131. data/test/test_50_name_stored.rb +305 -0
  132. data/test/test_51_name_print_area.rb +363 -0
  133. data/test/test_52_name_print_titles.rb +460 -0
  134. data/test/test_53_autofilter.rb +209 -0
  135. data/test/test_60_chart_generic.rb +576 -0
  136. data/test/test_61_chart_subclasses.rb +97 -0
  137. data/test/test_62_chart_formats.rb +270 -0
  138. data/test/test_63_chart_area_formats.rb +647 -0
  139. data/test/test_chartex.rb +35 -0
  140. data/test/ts_all.rb +46 -34
  141. data/writeexcel.gemspec +18 -0
  142. data/writeexcel.rdoc +583 -0
  143. metadata +162 -108
data/test/test_23_note.rb CHANGED
@@ -1,78 +1,78 @@
1
- ##########################################################################
2
- # test_23_note.rb
3
- #
4
- # Tests for some of the internal method used to write the NOTE record that
5
- # is used in cell comments.
6
- #
7
- # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
8
- #
9
- # original written in Perl by John McNamara
10
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
- #
12
- #########################################################################
13
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
14
-
15
- require "test/unit"
16
- require 'writeexcel'
17
-
18
- class TC_note < Test::Unit::TestCase
19
-
20
- def setup
21
- t = Time.now.strftime("%Y%m%d")
22
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
23
- @test_file = File.join(Dir.tmpdir, path)
24
- @workbook = Spreadsheet::WriteExcel.new(@test_file)
25
- @worksheet = @workbook.add_worksheet
26
- end
27
-
28
- def teardown
29
- @workbook.close
30
- File.unlink(@test_file) if FileTest.exist?(@test_file)
31
- end
32
-
33
- def test_blank_author_name
34
- data = @worksheet.comment_params(2,0,'Test')
35
- row = data[0]
36
- col = data[1]
37
- author = data[4]
38
- encoding = data[5]
39
- visible = data[6]
40
- obj_id = 1
41
-
42
- caption = sprintf(" \tstore_note")
43
- target = %w(
44
- 1C 00 0C 00 02 00 00 00 00 00 01 00 00 00 00 00
45
- ).join(' ')
46
- result = unpack_record(
47
- @worksheet.store_note(row,col,obj_id,author,encoding,visible))
48
- assert_equal(target, result, caption)
49
- end
50
-
51
- def test_defined_author_name
52
- data = @worksheet.comment_params(2,0,'Test', :author => 'Username')
53
- row = data[0]
54
- col = data[1]
55
- author = data[4]
56
- encoding = data[5]
57
- visible = data[6]
58
- obj_id = 1
59
-
60
- caption = sprintf(" \tstore_note")
61
- target = %w(
62
- 1C 00 14 00 02 00 00 00 00 00 01 00 08 00 00 55
63
- 73 65 72 6E 61 6D 65 00
64
- ).join(' ')
65
- result = unpack_record(
66
- @worksheet.store_note(row,col,obj_id,author,encoding,visible))
67
- assert_equal(target, result, caption)
68
- end
69
-
70
- ###############################################################################
71
- #
72
- # Unpack the binary data into a format suitable for printing in tests.
73
- #
74
- def unpack_record(data)
75
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
76
- end
77
-
78
- end
1
+ ##########################################################################
2
+ # test_23_note.rb
3
+ #
4
+ # Tests for some of the internal method used to write the NOTE record that
5
+ # is used in cell comments.
6
+ #
7
+ # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+ #########################################################################
13
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
14
+
15
+ require "test/unit"
16
+ require 'writeexcel'
17
+
18
+ class TC_note < Test::Unit::TestCase
19
+
20
+ def setup
21
+ t = Time.now.strftime("%Y%m%d")
22
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
23
+ @test_file = File.join(Dir.tmpdir, path)
24
+ @workbook = WriteExcel.new(@test_file)
25
+ @worksheet = @workbook.add_worksheet
26
+ end
27
+
28
+ def teardown
29
+ @workbook.close
30
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
31
+ end
32
+
33
+ def test_blank_author_name
34
+ data = @worksheet.comment_params(2,0,'Test')
35
+ row = data[0]
36
+ col = data[1]
37
+ author = data[4]
38
+ encoding = data[5]
39
+ visible = data[6]
40
+ obj_id = 1
41
+
42
+ caption = sprintf(" \tstore_note")
43
+ target = %w(
44
+ 1C 00 0C 00 02 00 00 00 00 00 01 00 00 00 00 00
45
+ ).join(' ')
46
+ result = unpack_record(
47
+ @worksheet.store_note(row,col,obj_id,author,encoding,visible))
48
+ assert_equal(target, result, caption)
49
+ end
50
+
51
+ def test_defined_author_name
52
+ data = @worksheet.comment_params(2,0,'Test', :author => 'Username')
53
+ row = data[0]
54
+ col = data[1]
55
+ author = data[4]
56
+ encoding = data[5]
57
+ visible = data[6]
58
+ obj_id = 1
59
+
60
+ caption = sprintf(" \tstore_note")
61
+ target = %w(
62
+ 1C 00 14 00 02 00 00 00 00 00 01 00 08 00 00 55
63
+ 73 65 72 6E 61 6D 65 00
64
+ ).join(' ')
65
+ result = unpack_record(
66
+ @worksheet.store_note(row,col,obj_id,author,encoding,visible))
67
+ assert_equal(target, result, caption)
68
+ end
69
+
70
+ ###############################################################################
71
+ #
72
+ # Unpack the binary data into a format suitable for printing in tests.
73
+ #
74
+ def unpack_record(data)
75
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
76
+ end
77
+
78
+ end
data/test/test_24_txo.rb CHANGED
@@ -1,80 +1,80 @@
1
- ##########################################################################
2
- # test_24_txo.rb
3
- #
4
- # Tests for some of the internal method used to write the NOTE record that
5
- # is used in cell comments.
6
- #
7
- # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
8
- #
9
- # original written in Perl by John McNamara
10
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
- #
12
- #########################################################################
13
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
14
-
15
- require "test/unit"
16
- require 'writeexcel'
17
-
18
- class TC_txo < Test::Unit::TestCase
19
-
20
- def setup
21
- t = Time.now.strftime("%Y%m%d")
22
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
23
- @test_file = File.join(Dir.tmpdir, path)
24
- @workbook = Spreadsheet::WriteExcel.new(@test_file)
25
- @worksheet = @workbook.add_worksheet
26
- end
27
-
28
- def teardown
29
- @workbook.close
30
- File.unlink(@test_file) if FileTest.exist?(@test_file)
31
- end
32
-
33
- def test_txo
34
- string = 'aaa'
35
- caption = " \t_store_txo()"
36
- target = %w(
37
- B6 01 12 00 12 02 00 00 00 00 00 00 00 00 03 00
38
- 10 00 00 00 00 00
39
- ).join(' ')
40
-
41
- result = unpack_record(@worksheet.store_txo(string.length))
42
- assert_equal(target, result, caption)
43
- end
44
-
45
- def test_first_continue_record_after_txo
46
- string = 'aaa'
47
- caption = " \t_store_txo_continue_1()"
48
- target = %w(
49
- 3C 00 04 00 00 61 61 61
50
- ).join(' ')
51
-
52
- result = unpack_record(@worksheet.store_txo_continue_1(string))
53
- assert_equal(target, result, caption)
54
- end
55
-
56
- def test_second_continue_record_after_txo
57
- string = 'aaa'
58
- caption = " \t_store_txo_continue_2()"
59
- target = %w(
60
- 3C 00 10 00 00 00 00 00 00 00 00 00 03 00 00 00
61
- 00 00 00 00
62
- ).join(' ')
63
- formats = [
64
- [0, 0],
65
- [string.length, 0]
66
- ]
67
-
68
- result = unpack_record(@worksheet.store_txo_continue_2(formats))
69
- assert_equal(target, result, caption)
70
- end
71
-
72
- ###############################################################################
73
- #
74
- # Unpack the binary data into a format suitable for printing in tests.
75
- #
76
- def unpack_record(data)
77
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
78
- end
79
-
80
- end
1
+ ##########################################################################
2
+ # test_24_txo.rb
3
+ #
4
+ # Tests for some of the internal method used to write the NOTE record that
5
+ # is used in cell comments.
6
+ #
7
+ # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+ #########################################################################
13
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
14
+
15
+ require "test/unit"
16
+ require 'writeexcel'
17
+
18
+ class TC_txo < Test::Unit::TestCase
19
+
20
+ def setup
21
+ t = Time.now.strftime("%Y%m%d")
22
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
23
+ @test_file = File.join(Dir.tmpdir, path)
24
+ @workbook = WriteExcel.new(@test_file)
25
+ @worksheet = @workbook.add_worksheet
26
+ end
27
+
28
+ def teardown
29
+ @workbook.close
30
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
31
+ end
32
+
33
+ def test_txo
34
+ string = 'aaa'
35
+ caption = " \t_store_txo()"
36
+ target = %w(
37
+ B6 01 12 00 12 02 00 00 00 00 00 00 00 00 03 00
38
+ 10 00 00 00 00 00
39
+ ).join(' ')
40
+
41
+ result = unpack_record(@worksheet.store_txo(string.length))
42
+ assert_equal(target, result, caption)
43
+ end
44
+
45
+ def test_first_continue_record_after_txo
46
+ string = 'aaa'
47
+ caption = " \t_store_txo_continue_1()"
48
+ target = %w(
49
+ 3C 00 04 00 00 61 61 61
50
+ ).join(' ')
51
+
52
+ result = unpack_record(@worksheet.store_txo_continue_1(string))
53
+ assert_equal(target, result, caption)
54
+ end
55
+
56
+ def test_second_continue_record_after_txo
57
+ string = 'aaa'
58
+ caption = " \t_store_txo_continue_2()"
59
+ target = %w(
60
+ 3C 00 10 00 00 00 00 00 00 00 00 00 03 00 00 00
61
+ 00 00 00 00
62
+ ).join(' ')
63
+ formats = [
64
+ [0, 0],
65
+ [string.length, 0]
66
+ ]
67
+
68
+ result = unpack_record(@worksheet.store_txo_continue_2(formats))
69
+ assert_equal(target, result, caption)
70
+ end
71
+
72
+ ###############################################################################
73
+ #
74
+ # Unpack the binary data into a format suitable for printing in tests.
75
+ #
76
+ def unpack_record(data)
77
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
78
+ end
79
+
80
+ end
@@ -0,0 +1,82 @@
1
+ ###############################################################################
2
+ #
3
+ # A test for Spreadsheet::WriteExcel.
4
+ #
5
+ # Tests for the _position_object() Worksheet method used to calculate the
6
+ # vertices that define the position of a graphical object within a worksheet.
7
+ #
8
+ # See the the _position_object() comments for a full explanation.
9
+ #
10
+ # reverse('ゥ'), September 2005, John McNamara, jmcnamara@cpan.org
11
+ #
12
+ # original written in Perl by John McNamara
13
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
14
+ #
15
+ #########################################################################
16
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
17
+
18
+ require "test/unit"
19
+ require 'writeexcel'
20
+ require 'stringio'
21
+
22
+ class TC_position_object < Test::Unit::TestCase
23
+
24
+ def setup
25
+ @test_file = StringIO.new
26
+ @workbook = WriteExcel.new(@test_file)
27
+ @worksheet = @workbook.add_worksheet
28
+ end
29
+
30
+ ###############################################################################
31
+ #
32
+ # Tests extracted from images imported into Excel.
33
+ #
34
+ #
35
+ # input = ($col_start, $row_start, $x1, $y1, $width, $height)
36
+ # (0, 1, 2, 3, 4, 5 )
37
+ #
38
+ # expected = ($col_start, $x1, $row_start, $y1, $col_end, $x2, $row_end, $y2)
39
+ # (0, 1, 2, 3, 4, 5, 6, 7 )
40
+ #
41
+ def test_extracted_from_images_imported_into_excel
42
+ tests = [
43
+ # Input # Expected results
44
+ [ [0, 0, 0, 0, 1, 1], [ 0, 0, 0, 0, 0, 16, 0, 15] ],
45
+ [ [0, 0, 0, 0, 2, 2], [ 0, 0, 0, 0, 0, 32, 0, 30] ],
46
+ [ [0, 0, 0, 0, 3, 3], [ 0, 0, 0, 0, 0, 48, 0, 45] ],
47
+ [ [0, 0, 0, 0, 4, 4], [ 0, 0, 0, 0, 0, 64, 0, 60] ],
48
+ [ [0, 0, 0, 0, 5, 5], [ 0, 0, 0, 0, 0, 80, 0, 75] ],
49
+ [ [0, 0, 0, 0, 6, 6], [ 0, 0, 0, 0, 0, 96, 0, 90] ],
50
+ [ [0, 0, 0, 0, 7, 7], [ 0, 0, 0, 0, 0, 112, 0, 105] ],
51
+ [ [0, 0, 0, 0, 8, 8], [ 0, 0, 0, 0, 0, 128, 0, 120] ],
52
+ [ [0, 0, 0, 0, 9, 9], [ 0, 0, 0, 0, 0, 144, 0, 136] ],
53
+ [ [0, 0, 0, 0, 10, 10], [ 0, 0, 0, 0, 0, 160, 0, 151] ],
54
+ [ [0, 0, 0, 0, 15, 15], [ 0, 0, 0, 0, 0, 240, 0, 226] ],
55
+ [ [0, 0, 0, 0, 16, 16], [ 0, 0, 0, 0, 0, 256, 0, 241] ],
56
+ [ [0, 0, 0, 0, 17, 17], [ 0, 0, 0, 0, 0, 272, 1, 0] ],
57
+ [ [0, 0, 0, 0, 18, 18], [ 0, 0, 0, 0, 0, 288, 1, 15] ],
58
+ [ [0, 0, 0, 0, 19, 19], [ 0, 0, 0, 0, 0, 304, 1, 30] ],
59
+ [ [0, 0, 0, 0, 62, 8], [ 0, 0, 0, 0, 0, 992, 0, 120] ],
60
+ [ [0, 0, 0, 0, 63, 8], [ 0, 0, 0, 0, 0, 1008, 0, 120] ],
61
+ [ [0, 0, 0, 0, 64, 8], [ 0, 0, 0, 0, 1, 0, 0, 120] ],
62
+ [ [0, 0, 0, 0, 65, 8], [ 0, 0, 0, 0, 1, 16, 0, 120] ],
63
+ [ [0, 0, 0, 0, 66, 8], [ 0, 0, 0, 0, 1, 32, 0, 120] ],
64
+ [ [0, 0, 0, 0, 200, 200], [ 0, 0, 0, 0, 3, 128, 11, 196] ],
65
+ [ [1, 4, 0, 0, 64, 16], [ 1, 0, 4, 0, 2, 0, 4, 241] ],
66
+ [ [1, 4, 1, 0, 64, 16], [ 1, 16, 4, 0, 2, 16, 4, 241] ],
67
+ [ [1, 4, 2, 0, 64, 16], [ 1, 32, 4, 0, 2, 32, 4, 241] ],
68
+ [ [1, 4, 2, 1, 64, 16], [ 1, 32, 4, 15, 2, 32, 5, 0] ],
69
+ [ [1, 4, 2, 2, 64, 16], [ 1, 32, 4, 30, 2, 32, 5, 15] ],
70
+
71
+ # Test for comment box standard sizes.
72
+ [ [2, 1, 15, 7, 128, 74], [ 2, 240, 1, 105, 4, 240, 5, 196] ]
73
+ ]
74
+
75
+ tests.each do |testcase|
76
+ input = testcase[0]
77
+ expected = testcase[1]
78
+ results = @worksheet.position_object(*input)
79
+ assert_equal(expected, results)
80
+ end
81
+ end
82
+ end
@@ -1,327 +1,327 @@
1
- ##########################################################################
2
- # test_26_autofilter.rb
3
- #
4
- # Tests for the internal methods used to write the AUTOFILTER record.
5
- #
6
- # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
7
- #
8
- # original written in Perl by John McNamara
9
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
10
- #
11
- #########################################################################
12
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
13
-
14
- require "test/unit"
15
- require 'writeexcel'
16
-
17
- class TC_26_autofilter < Test::Unit::TestCase
18
-
19
- def test_26_autofilter
20
- @tests.each do |test|
21
- column = test['column']
22
- expression = test['expression']
23
- tokens = @worksheet.extract_filter_tokens(expression)
24
- tokens = @worksheet.parse_filter_expression(expression, tokens)
25
-
26
- result = @worksheet.store_autofilter(column, *tokens)
27
-
28
- target = test['data'].join(" ")
29
-
30
- caption = " \tfilter_column(#{column}, '#{expression}')"
31
-
32
- result = unpack_record(result)
33
- assert_equal(target, result, caption)
34
- end
35
- end
36
-
37
- ###############################################################################
38
- #
39
- # Unpack the binary data into a format suitable for printing in tests.
40
- #
41
- def unpack_record(data)
42
- data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
43
- end
44
-
45
- def setup
46
- t = Time.now.strftime("%Y%m%d")
47
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
48
- @test_file = File.join(Dir.tmpdir, path)
49
- @workbook = Spreadsheet::WriteExcel.new(@test_file)
50
- @worksheet = @workbook.add_worksheet
51
- @tests = [
52
- {
53
- 'column' => 0,
54
- 'expression' => 'x = Blanks',
55
- 'data' => [%w(
56
- 9E 00 18 00 00 00 84 32 0C 02 00 00 00 00 00 00
57
- 00 00 00 00 00 00 00 00 00 00 00 00
58
-
59
- )]
60
- },
61
- {
62
- 'column' => 1,
63
- 'expression' => 'x = Nonblanks',
64
- 'data' => [%w(
65
- 9E 00 18 00 01 00 84 32 0E 05 00 00 00 00 00 00
66
- 00 00 00 00 00 00 00 00 00 00 00 00
67
-
68
- )]
69
- },
70
- {
71
- 'column' => 2,
72
- 'expression' => 'x > 1.001',
73
- 'data' => [%w(
74
- 9E 00 18 00 02 00 80 32 04 04 6A BC 74 93 18 04
75
- F0 3F 00 00 00 00 00 00 00 00 00 00
76
-
77
- )]
78
- },
79
- {
80
- 'column' => 3,
81
- 'expression' => 'x >= 1.001',
82
- 'data' => [%w(
83
- 9E 00 18 00 03 00 80 32 04 06 6A BC 74 93 18 04
84
- F0 3F 00 00 00 00 00 00 00 00 00 00
85
-
86
- )]
87
- },
88
- {
89
- 'column' => 4,
90
- 'expression' => 'x < 1.001',
91
- 'data' => [%w(
92
- 9E 00 18 00 04 00 80 32 04 01 6A BC 74 93 18 04
93
- F0 3F 00 00 00 00 00 00 00 00 00 00
94
-
95
- )]
96
- },
97
- {
98
- 'column' => 5,
99
- 'expression' => 'x <= 1.001',
100
- 'data' => [%w(
101
- 9E 00 18 00 05 00 80 32 04 03 6A BC 74 93 18 04
102
- F0 3F 00 00 00 00 00 00 00 00 00 00
103
-
104
- )]
105
- },
106
- {
107
- 'column' => 6,
108
- 'expression' => 'x > 1.001 and x <= 5.001',
109
- 'data' => [%w(
110
- 9E 00 18 00 06 00 80 32 04 04 6A BC 74 93 18 04
111
- F0 3F 04 03 1B 2F DD 24 06 01 14 40
112
-
113
- )]
114
- },
115
- {
116
- 'column' => 7,
117
- 'expression' => 'x > 1.001 or x <= 5.001',
118
- 'data' => [%w(
119
- 9E 00 18 00 07 00 81 32 04 04 6A BC 74 93 18 04
120
- F0 3F 04 03 1B 2F DD 24 06 01 14 40
121
-
122
- )]
123
- },
124
- {
125
- 'column' => 8,
126
- 'expression' => 'x <> 2.001',
127
- 'data' => [%w(
128
- 9E 00 18 00 08 00 80 32 04 05 35 5E BA 49 0C 02
129
- 00 40 00 00 00 00 00 00 00 00 00 00
130
-
131
- )]
132
- },
133
- {
134
- 'column' => 9,
135
- 'expression' => 'x = 1.001',
136
- 'data' => [%w(
137
- 9E 00 1E 00 09 00 84 32 06 02 00 00 00 00 05 00
138
- 00 00 00 00 00 00 00 00 00 00 00 00 00 31 2E 30
139
- 30 31
140
-
141
- )]
142
- },
143
- {
144
- 'column' => 10,
145
- 'expression' => 'x = West',
146
- 'data' => [%w(
147
- 9E 00 1D 00 0A 00 84 32 06 02 00 00 00 00 04 00
148
- 00 00 00 00 00 00 00 00 00 00 00 00 00 57 65 73
149
- 74
150
-
151
- )]
152
- },
153
- {
154
- 'column' => 11,
155
- 'expression' => 'x = East',
156
- 'data' => [%w(
157
- 9E 00 1D 00 0B 00 84 32 06 02 00 00 00 00 04 00
158
- 00 00 00 00 00 00 00 00 00 00 00 00 00 45 61 73
159
- 74
160
-
161
- )]
162
- },
163
- {
164
- 'column' => 12,
165
- 'expression' => 'x <> West',
166
- 'data' => [%w(
167
- 9E 00 1D 00 0C 00 80 32 06 05 00 00 00 00 04 00
168
- 00 00 00 00 00 00 00 00 00 00 00 00 00 57 65 73
169
- 74
170
-
171
- )]
172
- },
173
- {
174
- 'column' => 13,
175
- 'expression' => 'x =~ b*',
176
- 'data' => [%w(
177
- 9E 00 1B 00 0D 00 80 32 06 02 00 00 00 00 02 00
178
- 00 00 00 00 00 00 00 00 00 00 00 00 00 62 2A
179
-
180
- )]
181
- },
182
- {
183
- 'column' => 14,
184
- 'expression' => 'x !~ b*',
185
- 'data' => [%w(
186
- 9E 00 1B 00 0E 00 80 32 06 05 00 00 00 00 02 00
187
- 00 00 00 00 00 00 00 00 00 00 00 00 00 62 2A
188
-
189
- )]
190
- },
191
- {
192
- 'column' => 15,
193
- 'expression' => 'x =~ *b',
194
- 'data' => [%w(
195
- 9E 00 1B 00 0F 00 80 32 06 02 00 00 00 00 02 00
196
- 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62
197
-
198
- )]
199
- },
200
- {
201
- 'column' => 16,
202
- 'expression' => 'x !~ *b',
203
- 'data' => [%w(
204
- 9E 00 1B 00 10 00 80 32 06 05 00 00 00 00 02 00
205
- 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62
206
-
207
- )]
208
- },
209
- {
210
- 'column' => 17,
211
- 'expression' => 'x =~ *b*',
212
- 'data' => [%w(
213
- 9E 00 1C 00 11 00 80 32 06 02 00 00 00 00 03 00
214
- 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62 2A
215
-
216
- )]
217
- },
218
- {
219
- 'column' => 18,
220
- 'expression' => 'x !~ *b*',
221
- 'data' => [%w(
222
- 9E 00 1C 00 12 00 80 32 06 05 00 00 00 00 03 00
223
- 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62 2A
224
-
225
- )]
226
- },
227
- {
228
- 'column' => 19,
229
- 'expression' => 'x = fo?',
230
- 'data' => [%w(
231
- 9E 00 1C 00 13 00 80 32 06 02 00 00 00 00 03 00
232
- 00 00 00 00 00 00 00 00 00 00 00 00 00 66 6F 3F
233
-
234
- )]
235
- },
236
- {
237
- 'column' => 20,
238
- 'expression' => 'x = fo~?',
239
- 'data' => [%w(
240
- 9E 00 1D 00 14 00 80 32 06 02 00 00 00 00 04 00
241
- 00 00 00 00 00 00 00 00 00 00 00 00 00 66 6F 7E
242
- 3F
243
-
244
- )]
245
- },
246
- {
247
- 'column' => 21,
248
- 'expression' => 'x = East and x = West',
249
- 'data' => [%w(
250
- 9E 00 22 00 15 00 8C 32 06 02 00 00 00 00 04 00
251
- 00 00 06 02 00 00 00 00 04 00 00 00 00 45 61 73
252
- 74 00 57 65 73 74
253
-
254
- )]
255
- },
256
- {
257
- 'column' => 22,
258
- 'expression' => 'top 10 items',
259
- 'data' => [%w(
260
- 9E 00 18 00 16 00 30 05 04 06 00 00 00 00 00 00
261
- 00 00 00 00 00 00 00 00 00 00 00 00
262
-
263
- )]
264
- },
265
- {
266
- 'column' => 23,
267
- 'expression' => 'top 10 %',
268
- 'data' => [%w(
269
- 9E 00 18 00 17 00 70 05 04 06 00 00 00 00 00 00
270
- 00 00 00 00 00 00 00 00 00 00 00 00
271
-
272
- )]
273
- },
274
- {
275
- 'column' => 24,
276
- 'expression' => 'bottom 10 items',
277
- 'data' => [%w(
278
- 9E 00 18 00 18 00 10 05 04 03 00 00 00 00 00 00
279
- 00 00 00 00 00 00 00 00 00 00 00 00
280
-
281
- )]
282
- },
283
- {
284
- 'column' => 25,
285
- 'expression' => 'bottom 10 %',
286
- 'data' => [%w(
287
- 9E 00 18 00 19 00 50 05 04 03 00 00 00 00 00 00
288
- 00 00 00 00 00 00 00 00 00 00 00 00
289
-
290
- )]
291
- },
292
- {
293
- 'column' => 26,
294
- 'expression' => 'top 5 items',
295
- 'data' => [%w(
296
- 9E 00 18 00 1A 00 B0 02 04 06 00 00 00 00 00 00
297
- 00 00 00 00 00 00 00 00 00 00 00 00
298
-
299
- )]
300
- },
301
- {
302
- 'column' => 27,
303
- 'expression' => 'top 100 items',
304
- 'data' => [%w(
305
- 9E 00 18 00 1B 00 30 32 04 06 00 00 00 00 00 00
306
- 00 00 00 00 00 00 00 00 00 00 00 00
307
-
308
- )]
309
- },
310
- {
311
- 'column' => 28,
312
- 'expression' => 'top 101 items',
313
- 'data' => [%w(
314
- 9E 00 18 00 1C 00 B0 32 04 06 00 00 00 00 00 00
315
- 00 00 00 00 00 00 00 00 00 00 00 00
316
-
317
- )]
318
- }
319
- ]
320
- end
321
-
322
- def teardown
323
- @workbook.close
324
- File.unlink(@test_file) if FileTest.exist?(@test_file)
325
- end
326
-
327
- end
1
+ ##########################################################################
2
+ # test_26_autofilter.rb
3
+ #
4
+ # Tests for the internal methods used to write the AUTOFILTER record.
5
+ #
6
+ # reverse('©'), September 2005, John McNamara, jmcnamara@cpan.org
7
+ #
8
+ # original written in Perl by John McNamara
9
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
10
+ #
11
+ #########################################################################
12
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
13
+
14
+ require "test/unit"
15
+ require 'writeexcel'
16
+
17
+ class TC_26_autofilter < Test::Unit::TestCase
18
+
19
+ def test_26_autofilter
20
+ @tests.each do |test|
21
+ column = test['column']
22
+ expression = test['expression']
23
+ tokens = @worksheet.extract_filter_tokens(expression)
24
+ tokens = @worksheet.parse_filter_expression(expression, tokens)
25
+
26
+ result = @worksheet.store_autofilter(column, *tokens)
27
+
28
+ target = test['data'].join(" ")
29
+
30
+ caption = " \tfilter_column(#{column}, '#{expression}')"
31
+
32
+ result = unpack_record(result)
33
+ assert_equal(target, result, caption)
34
+ end
35
+ end
36
+
37
+ ###############################################################################
38
+ #
39
+ # Unpack the binary data into a format suitable for printing in tests.
40
+ #
41
+ def unpack_record(data)
42
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
43
+ end
44
+
45
+ def setup
46
+ t = Time.now.strftime("%Y%m%d")
47
+ path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
48
+ @test_file = File.join(Dir.tmpdir, path)
49
+ @workbook = WriteExcel.new(@test_file)
50
+ @worksheet = @workbook.add_worksheet
51
+ @tests = [
52
+ {
53
+ 'column' => 0,
54
+ 'expression' => 'x = Blanks',
55
+ 'data' => [%w(
56
+ 9E 00 18 00 00 00 84 32 0C 02 00 00 00 00 00 00
57
+ 00 00 00 00 00 00 00 00 00 00 00 00
58
+
59
+ )]
60
+ },
61
+ {
62
+ 'column' => 1,
63
+ 'expression' => 'x = Nonblanks',
64
+ 'data' => [%w(
65
+ 9E 00 18 00 01 00 84 32 0E 05 00 00 00 00 00 00
66
+ 00 00 00 00 00 00 00 00 00 00 00 00
67
+
68
+ )]
69
+ },
70
+ {
71
+ 'column' => 2,
72
+ 'expression' => 'x > 1.001',
73
+ 'data' => [%w(
74
+ 9E 00 18 00 02 00 80 32 04 04 6A BC 74 93 18 04
75
+ F0 3F 00 00 00 00 00 00 00 00 00 00
76
+
77
+ )]
78
+ },
79
+ {
80
+ 'column' => 3,
81
+ 'expression' => 'x >= 1.001',
82
+ 'data' => [%w(
83
+ 9E 00 18 00 03 00 80 32 04 06 6A BC 74 93 18 04
84
+ F0 3F 00 00 00 00 00 00 00 00 00 00
85
+
86
+ )]
87
+ },
88
+ {
89
+ 'column' => 4,
90
+ 'expression' => 'x < 1.001',
91
+ 'data' => [%w(
92
+ 9E 00 18 00 04 00 80 32 04 01 6A BC 74 93 18 04
93
+ F0 3F 00 00 00 00 00 00 00 00 00 00
94
+
95
+ )]
96
+ },
97
+ {
98
+ 'column' => 5,
99
+ 'expression' => 'x <= 1.001',
100
+ 'data' => [%w(
101
+ 9E 00 18 00 05 00 80 32 04 03 6A BC 74 93 18 04
102
+ F0 3F 00 00 00 00 00 00 00 00 00 00
103
+
104
+ )]
105
+ },
106
+ {
107
+ 'column' => 6,
108
+ 'expression' => 'x > 1.001 and x <= 5.001',
109
+ 'data' => [%w(
110
+ 9E 00 18 00 06 00 80 32 04 04 6A BC 74 93 18 04
111
+ F0 3F 04 03 1B 2F DD 24 06 01 14 40
112
+
113
+ )]
114
+ },
115
+ {
116
+ 'column' => 7,
117
+ 'expression' => 'x > 1.001 or x <= 5.001',
118
+ 'data' => [%w(
119
+ 9E 00 18 00 07 00 81 32 04 04 6A BC 74 93 18 04
120
+ F0 3F 04 03 1B 2F DD 24 06 01 14 40
121
+
122
+ )]
123
+ },
124
+ {
125
+ 'column' => 8,
126
+ 'expression' => 'x <> 2.001',
127
+ 'data' => [%w(
128
+ 9E 00 18 00 08 00 80 32 04 05 35 5E BA 49 0C 02
129
+ 00 40 00 00 00 00 00 00 00 00 00 00
130
+
131
+ )]
132
+ },
133
+ {
134
+ 'column' => 9,
135
+ 'expression' => 'x = 1.001',
136
+ 'data' => [%w(
137
+ 9E 00 1E 00 09 00 84 32 06 02 00 00 00 00 05 00
138
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 31 2E 30
139
+ 30 31
140
+
141
+ )]
142
+ },
143
+ {
144
+ 'column' => 10,
145
+ 'expression' => 'x = West',
146
+ 'data' => [%w(
147
+ 9E 00 1D 00 0A 00 84 32 06 02 00 00 00 00 04 00
148
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 57 65 73
149
+ 74
150
+
151
+ )]
152
+ },
153
+ {
154
+ 'column' => 11,
155
+ 'expression' => 'x = East',
156
+ 'data' => [%w(
157
+ 9E 00 1D 00 0B 00 84 32 06 02 00 00 00 00 04 00
158
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 45 61 73
159
+ 74
160
+
161
+ )]
162
+ },
163
+ {
164
+ 'column' => 12,
165
+ 'expression' => 'x <> West',
166
+ 'data' => [%w(
167
+ 9E 00 1D 00 0C 00 80 32 06 05 00 00 00 00 04 00
168
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 57 65 73
169
+ 74
170
+
171
+ )]
172
+ },
173
+ {
174
+ 'column' => 13,
175
+ 'expression' => 'x =~ b*',
176
+ 'data' => [%w(
177
+ 9E 00 1B 00 0D 00 80 32 06 02 00 00 00 00 02 00
178
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 62 2A
179
+
180
+ )]
181
+ },
182
+ {
183
+ 'column' => 14,
184
+ 'expression' => 'x !~ b*',
185
+ 'data' => [%w(
186
+ 9E 00 1B 00 0E 00 80 32 06 05 00 00 00 00 02 00
187
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 62 2A
188
+
189
+ )]
190
+ },
191
+ {
192
+ 'column' => 15,
193
+ 'expression' => 'x =~ *b',
194
+ 'data' => [%w(
195
+ 9E 00 1B 00 0F 00 80 32 06 02 00 00 00 00 02 00
196
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62
197
+
198
+ )]
199
+ },
200
+ {
201
+ 'column' => 16,
202
+ 'expression' => 'x !~ *b',
203
+ 'data' => [%w(
204
+ 9E 00 1B 00 10 00 80 32 06 05 00 00 00 00 02 00
205
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62
206
+
207
+ )]
208
+ },
209
+ {
210
+ 'column' => 17,
211
+ 'expression' => 'x =~ *b*',
212
+ 'data' => [%w(
213
+ 9E 00 1C 00 11 00 80 32 06 02 00 00 00 00 03 00
214
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62 2A
215
+
216
+ )]
217
+ },
218
+ {
219
+ 'column' => 18,
220
+ 'expression' => 'x !~ *b*',
221
+ 'data' => [%w(
222
+ 9E 00 1C 00 12 00 80 32 06 05 00 00 00 00 03 00
223
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 62 2A
224
+
225
+ )]
226
+ },
227
+ {
228
+ 'column' => 19,
229
+ 'expression' => 'x = fo?',
230
+ 'data' => [%w(
231
+ 9E 00 1C 00 13 00 80 32 06 02 00 00 00 00 03 00
232
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 66 6F 3F
233
+
234
+ )]
235
+ },
236
+ {
237
+ 'column' => 20,
238
+ 'expression' => 'x = fo~?',
239
+ 'data' => [%w(
240
+ 9E 00 1D 00 14 00 80 32 06 02 00 00 00 00 04 00
241
+ 00 00 00 00 00 00 00 00 00 00 00 00 00 66 6F 7E
242
+ 3F
243
+
244
+ )]
245
+ },
246
+ {
247
+ 'column' => 21,
248
+ 'expression' => 'x = East and x = West',
249
+ 'data' => [%w(
250
+ 9E 00 22 00 15 00 8C 32 06 02 00 00 00 00 04 00
251
+ 00 00 06 02 00 00 00 00 04 00 00 00 00 45 61 73
252
+ 74 00 57 65 73 74
253
+
254
+ )]
255
+ },
256
+ {
257
+ 'column' => 22,
258
+ 'expression' => 'top 10 items',
259
+ 'data' => [%w(
260
+ 9E 00 18 00 16 00 30 05 04 06 00 00 00 00 00 00
261
+ 00 00 00 00 00 00 00 00 00 00 00 00
262
+
263
+ )]
264
+ },
265
+ {
266
+ 'column' => 23,
267
+ 'expression' => 'top 10 %',
268
+ 'data' => [%w(
269
+ 9E 00 18 00 17 00 70 05 04 06 00 00 00 00 00 00
270
+ 00 00 00 00 00 00 00 00 00 00 00 00
271
+
272
+ )]
273
+ },
274
+ {
275
+ 'column' => 24,
276
+ 'expression' => 'bottom 10 items',
277
+ 'data' => [%w(
278
+ 9E 00 18 00 18 00 10 05 04 03 00 00 00 00 00 00
279
+ 00 00 00 00 00 00 00 00 00 00 00 00
280
+
281
+ )]
282
+ },
283
+ {
284
+ 'column' => 25,
285
+ 'expression' => 'bottom 10 %',
286
+ 'data' => [%w(
287
+ 9E 00 18 00 19 00 50 05 04 03 00 00 00 00 00 00
288
+ 00 00 00 00 00 00 00 00 00 00 00 00
289
+
290
+ )]
291
+ },
292
+ {
293
+ 'column' => 26,
294
+ 'expression' => 'top 5 items',
295
+ 'data' => [%w(
296
+ 9E 00 18 00 1A 00 B0 02 04 06 00 00 00 00 00 00
297
+ 00 00 00 00 00 00 00 00 00 00 00 00
298
+
299
+ )]
300
+ },
301
+ {
302
+ 'column' => 27,
303
+ 'expression' => 'top 100 items',
304
+ 'data' => [%w(
305
+ 9E 00 18 00 1B 00 30 32 04 06 00 00 00 00 00 00
306
+ 00 00 00 00 00 00 00 00 00 00 00 00
307
+
308
+ )]
309
+ },
310
+ {
311
+ 'column' => 28,
312
+ 'expression' => 'top 101 items',
313
+ 'data' => [%w(
314
+ 9E 00 18 00 1C 00 B0 32 04 06 00 00 00 00 00 00
315
+ 00 00 00 00 00 00 00 00 00 00 00 00
316
+
317
+ )]
318
+ }
319
+ ]
320
+ end
321
+
322
+ def teardown
323
+ @workbook.close
324
+ File.unlink(@test_file) if FileTest.exist?(@test_file)
325
+ end
326
+
327
+ end