writeexcel 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitattributes +1 -0
  2. data/README.rdoc +12 -6
  3. data/VERSION +1 -1
  4. data/charts/chartex.rb +316 -315
  5. data/charts/demo1.rb +1 -0
  6. data/charts/demo2.rb +1 -0
  7. data/charts/demo3.rb +117 -116
  8. data/charts/demo4.rb +119 -118
  9. data/charts/demo5.rb +48 -47
  10. data/examples/a_simple.rb +1 -0
  11. data/examples/autofilter.rb +1 -0
  12. data/examples/bigfile.rb +30 -29
  13. data/examples/chart_area.rb +121 -120
  14. data/examples/chart_bar.rb +120 -119
  15. data/examples/chart_column.rb +120 -119
  16. data/examples/chart_line.rb +120 -119
  17. data/examples/chart_pie.rb +108 -107
  18. data/examples/chart_scatter.rb +121 -120
  19. data/examples/chart_stock.rb +148 -147
  20. data/examples/chess.rb +1 -0
  21. data/examples/colors.rb +1 -0
  22. data/examples/comments1.rb +1 -0
  23. data/examples/comments2.rb +3 -2
  24. data/examples/copyformat.rb +1 -0
  25. data/examples/data_validate.rb +1 -0
  26. data/examples/date_time.rb +1 -0
  27. data/examples/defined_name.rb +1 -0
  28. data/examples/demo.rb +1 -0
  29. data/examples/diag_border.rb +1 -0
  30. data/examples/formats.rb +1 -0
  31. data/examples/formula_result.rb +1 -0
  32. data/examples/header.rb +1 -0
  33. data/examples/hide_sheet.rb +1 -0
  34. data/examples/hyperlink.rb +1 -0
  35. data/examples/images.rb +1 -0
  36. data/examples/indent.rb +1 -0
  37. data/examples/merge1.rb +1 -0
  38. data/examples/merge2.rb +1 -0
  39. data/examples/merge3.rb +1 -0
  40. data/examples/merge4.rb +1 -0
  41. data/examples/merge5.rb +1 -0
  42. data/examples/merge6.rb +67 -66
  43. data/examples/outline.rb +1 -0
  44. data/examples/outline_collapsed.rb +1 -0
  45. data/examples/panes.rb +1 -0
  46. data/examples/properties.rb +1 -0
  47. data/examples/properties_jp.rb +1 -0
  48. data/examples/protection.rb +1 -0
  49. data/examples/regions.rb +1 -0
  50. data/examples/repeat.rb +1 -0
  51. data/examples/right_to_left.rb +1 -0
  52. data/examples/row_wrap.rb +1 -0
  53. data/examples/stats.rb +1 -0
  54. data/examples/stocks.rb +1 -0
  55. data/examples/tab_colors.rb +1 -0
  56. data/examples/write_arrays.rb +1 -0
  57. data/lib/writeexcel.rb +6 -1
  58. data/lib/writeexcel/biffwriter.rb +21 -20
  59. data/lib/writeexcel/chart.rb +25 -12
  60. data/lib/writeexcel/charts/area.rb +153 -152
  61. data/lib/writeexcel/charts/bar.rb +178 -177
  62. data/lib/writeexcel/charts/column.rb +157 -156
  63. data/lib/writeexcel/charts/external.rb +62 -61
  64. data/lib/writeexcel/charts/line.rb +153 -152
  65. data/lib/writeexcel/charts/pie.rb +170 -169
  66. data/lib/writeexcel/charts/scatter.rb +4 -3
  67. data/lib/writeexcel/charts/stock.rb +212 -211
  68. data/lib/writeexcel/compatibility.rb +320 -0
  69. data/lib/writeexcel/excelformulaparser.rb +587 -586
  70. data/lib/writeexcel/format.rb +12 -13
  71. data/lib/writeexcel/formula.rb +30 -28
  72. data/lib/writeexcel/helper.rb +23 -0
  73. data/lib/writeexcel/olewriter.rb +5 -16
  74. data/lib/writeexcel/properties.rb +43 -54
  75. data/lib/writeexcel/storage_lite.rb +981 -968
  76. data/lib/writeexcel/workbook.rb +94 -73
  77. data/lib/writeexcel/worksheet.rb +230 -210
  78. data/test/helper.rb +19 -0
  79. data/test/test_00_IEEE_double.rb +1 -0
  80. data/test/test_01_add_worksheet.rb +1 -0
  81. data/test/test_02_merge_formats.rb +3 -5
  82. data/test/test_04_dimensions.rb +3 -5
  83. data/test/test_05_rows.rb +6 -6
  84. data/test/test_06_extsst.rb +8 -8
  85. data/test/test_11_date_time.rb +3 -5
  86. data/test/test_12_date_only.rb +3 -5
  87. data/test/test_13_date_seconds.rb +4 -6
  88. data/test/test_21_escher.rb +3 -5
  89. data/test/test_22_mso_drawing_group.rb +20 -22
  90. data/test/test_23_note.rb +5 -7
  91. data/test/test_24_txo.rb +3 -5
  92. data/test/test_25_position_object.rb +84 -79
  93. data/test/test_26_autofilter.rb +3 -13
  94. data/test/test_27_autofilter.rb +3 -13
  95. data/test/test_28_autofilter.rb +3 -13
  96. data/test/test_29_process_jpg.rb +5 -0
  97. data/test/test_30_validation_dval.rb +3 -5
  98. data/test/test_31_validation_dv_strings.rb +3 -5
  99. data/test/test_32_validation_dv_formula.rb +3 -5
  100. data/test/test_40_property_types.rb +10 -9
  101. data/test/test_41_properties.rb +1 -0
  102. data/test/test_42_set_properties.rb +14 -15
  103. data/test/test_50_name_stored.rb +299 -302
  104. data/test/test_51_name_print_area.rb +357 -360
  105. data/test/test_52_name_print_titles.rb +454 -457
  106. data/test/test_53_autofilter.rb +203 -206
  107. data/test/test_60_chart_generic.rb +5 -0
  108. data/test/test_61_chart_subclasses.rb +95 -94
  109. data/test/test_62_chart_formats.rb +272 -267
  110. data/test/test_63_chart_area_formats.rb +649 -644
  111. data/test/test_biff.rb +12 -38
  112. data/test/test_compatibility.rb +627 -0
  113. data/test/test_example_match.rb +3 -18
  114. data/test/test_format.rb +46 -105
  115. data/test/test_formula.rb +1 -0
  116. data/test/test_ole.rb +3 -4
  117. data/test/test_storage_lite.rb +125 -146
  118. data/test/test_workbook.rb +2 -23
  119. data/test/test_worksheet.rb +4 -5
  120. data/utils/add_magic_comment.rb +80 -0
  121. data/writeexcel.gemspec +8 -2
  122. metadata +10 -4
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'rubygems'
2
3
  require 'test/unit'
3
4
 
@@ -6,4 +7,22 @@
6
7
  require 'writeexcel'
7
8
 
8
9
  class Test::Unit::TestCase
10
+ ###############################################################################
11
+ #
12
+ # Unpack the binary data into a format suitable for printing in tests.
13
+ #
14
+ def unpack_record(data)
15
+ data.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ')
16
+ end
17
+
18
+ # expected : existing file path
19
+ # target : io (ex) string io object where stored data.
20
+ def compare_file(expected, target)
21
+ # target is StringIO object.
22
+ assert_equal(
23
+ File.binread(expected),
24
+ target.string.force_encoding('BINARY'),
25
+ "#{File.basename(expected)} doesn't match."
26
+ )
27
+ end
9
28
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'helper'
2
3
 
3
4
  class TC_BIFFWriter < Test::Unit::TestCase
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'helper'
2
3
 
3
4
  class TC_add_worksheet < Test::Unit::TestCase
@@ -1,12 +1,11 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'helper'
3
+ require 'stringio'
2
4
 
3
5
  class TC_merge_formats < Test::Unit::TestCase
4
6
 
5
7
  def setup
6
- t = Time.now.strftime("%Y%m%d")
7
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
8
- @test_file = File.join(Dir.tmpdir, path)
9
- @workbook = WriteExcel.new(@test_file)
8
+ @workbook = WriteExcel.new(StringIO.new)
10
9
  @worksheet = @workbook.add_worksheet
11
10
  @merged_format = @workbook.add_format(:bold => 1)
12
11
  @non_merged_format = @workbook.add_format(:bold => 1)
@@ -17,7 +16,6 @@ def setup
17
16
 
18
17
  def teardown
19
18
  @workbook.close
20
- File.unlink(@test_file) if FileTest.exist?(@test_file)
21
19
  end
22
20
 
23
21
  def test_some
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # A test for WriteExcel.
@@ -11,14 +12,12 @@
11
12
  #
12
13
  ############################################################################
13
14
  require 'helper'
15
+ require 'stringio'
14
16
 
15
17
  class TC_dimensions < Test::Unit::TestCase
16
18
 
17
19
  def setup
18
- t = Time.now.strftime("%Y%m%d")
19
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
20
- @test_file = File.join(Dir.tmpdir, path)
21
- @workbook = WriteExcel.new(@test_file)
20
+ @workbook = WriteExcel.new(StringIO.new)
22
21
  @worksheet = @workbook.add_worksheet
23
22
  @format = @workbook.add_format
24
23
  @dims = ['row_min', 'row_max', 'col_min', 'col_max']
@@ -27,7 +26,6 @@ def setup
27
26
 
28
27
  def teardown
29
28
  @workbook.close
30
- File.unlink(@test_file) if FileTest.exist?(@test_file)
31
29
  end
32
30
 
33
31
  def test_no_worksheet_cell_data
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # A test for WriteExcel.
@@ -11,6 +12,7 @@
11
12
  #
12
13
  ############################################################################
13
14
  require 'helper'
15
+ require 'stringio'
14
16
 
15
17
  class TC_rows < Test::Unit::TestCase
16
18
 
@@ -18,10 +20,8 @@ def setup
18
20
  end
19
21
 
20
22
  def test_1
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)
23
+ file = StringIO.new
24
+ workbook = WriteExcel.new(file)
25
25
  workbook.compatibility_mode(1)
26
26
  @tests = []
27
27
 
@@ -150,7 +150,8 @@ def test_1
150
150
  # Read in the row records
151
151
  rows = []
152
152
 
153
- xlsfile = open(@test_file, "rb")
153
+ xlsfile = StringIO.new(file.string)
154
+
154
155
  while header = xlsfile.read(4)
155
156
  record, length = header.unpack('vv')
156
157
  data = xlsfile.read(length)
@@ -173,7 +174,6 @@ def test_1
173
174
  end
174
175
 
175
176
  def teardown
176
- File.unlink(@test_file) if FileTest.exist?(@test_file)
177
177
  end
178
178
 
179
179
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # A test for WriteExcel.
@@ -23,9 +24,6 @@
23
24
  class TC_extsst < Test::Unit::TestCase
24
25
 
25
26
  def setup
26
- io = StringIO.new
27
- @workbook = WriteExcel.new(io)
28
-
29
27
  @tests = [ # Unique Number of Bucket
30
28
  # strings buckets size
31
29
  [0, 0, 8],
@@ -61,17 +59,19 @@ def setup
61
59
 
62
60
  def test_to_tests
63
61
  @tests.each do |test|
62
+ io = StringIO.new
63
+ workbook = WriteExcel.new(io)
64
+ workbook.not_using_tmpfile
64
65
 
65
66
  str_unique = test[0]
66
67
 
67
- @workbook.str_unique = str_unique
68
- @workbook.calculate_extsst_size
68
+ workbook.str_unique = str_unique
69
+ workbook.calculate_extsst_size
69
70
 
70
- assert_equal(test[1], @workbook.extsst_buckets,
71
+ assert_equal(test[1], workbook.extsst_buckets,
71
72
  " \tBucket number for #{str_unique} strings")
72
- assert_equal(test[2], @workbook.extsst_bucket_size,
73
+ assert_equal(test[2], workbook.extsst_bucket_size,
73
74
  " \tBucket size for #{str_unique} strings")
74
75
  end
75
76
  end
76
-
77
77
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # A test for WriteExcel.
@@ -11,21 +12,18 @@
11
12
  #
12
13
  ############################################################################
13
14
  require 'helper'
15
+ require 'stringio'
14
16
 
15
17
  class TC_data_time < Test::Unit::TestCase
16
18
 
17
19
  def setup
18
- t = Time.now.strftime("%Y%m%d")
19
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
20
- @test_file = File.join(Dir.tmpdir, path)
21
- @workbook = WriteExcel.new(@test_file)
20
+ @workbook = WriteExcel.new(StringIO.new)
22
21
  @worksheet = @workbook.add_worksheet
23
22
  @fit_delta = 0.5/(24*60*60*1000)
24
23
  end
25
24
 
26
25
  def teardown
27
26
  @workbook.close
28
- File.unlink(@test_file) if FileTest.exist?(@test_file)
29
27
  end
30
28
 
31
29
  def fit_cmp(a, b)
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # A test for WriteExcel.
@@ -11,20 +12,17 @@
11
12
  #
12
13
  ############################################################################
13
14
  require 'helper'
15
+ require 'stringio'
14
16
 
15
17
  class TC_data_only < Test::Unit::TestCase
16
18
 
17
19
  def setup
18
- t = Time.now.strftime("%Y%m%d")
19
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
20
- @test_file = File.join(Dir.tmpdir, path)
21
- @workbook = WriteExcel.new(@test_file)
20
+ @workbook = WriteExcel.new(StringIO.new)
22
21
  @worksheet = @workbook.add_worksheet
23
22
  end
24
23
 
25
24
  def teardown
26
25
  @workbook.close
27
- File.unlink(@test_file) if FileTest.exist?(@test_file)
28
26
  end
29
27
 
30
28
  def test_the_dates_generated_by_excel
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # A test for WriteExcel.
@@ -11,21 +12,18 @@
11
12
  #
12
13
  ############################################################################
13
14
  require 'helper'
15
+ require 'stringio'
14
16
 
15
17
  class TC_data_seconds < Test::Unit::TestCase
16
18
 
17
19
  def setup
18
- t = Time.now.strftime("%Y%m%d")
19
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
20
- @test_file = File.join(Dir.tmpdir, path)
21
- @workbook = WriteExcel.new(@test_file)
20
+ @workbook = WriteExcel.new(StringIO.new)
22
21
  @worksheet = @workbook.add_worksheet
23
- @fit_delta = 0.5/(24*60*60*1000)
22
+ @fit_delta = 0.5/(24 * 60 * 60 * 1000)
24
23
  end
25
24
 
26
25
  def teardown
27
26
  @workbook.close
28
- File.unlink(@test_file) if FileTest.exist?(@test_file)
29
27
  end
30
28
 
31
29
  def fit_cmp(a, b)
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # A test for WriteExcel.
@@ -19,20 +20,17 @@
19
20
  #
20
21
  ############################################################################
21
22
  require 'helper'
23
+ require 'stringio'
22
24
 
23
25
  class TC_escher < Test::Unit::TestCase
24
26
 
25
27
  def setup
26
- t = Time.now.strftime("%Y%m%d")
27
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
28
- @test_file = File.join(Dir.tmpdir, path)
29
- @workbook = WriteExcel.new(@test_file)
28
+ @workbook = WriteExcel.new(StringIO.new)
30
29
  @worksheet = @workbook.add_worksheet
31
30
  end
32
31
 
33
32
  def teardown
34
33
  @workbook.close
35
- File.unlink(@test_file) if FileTest.exist?(@test_file)
36
34
  end
37
35
 
38
36
  def test_dummy
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ##########################################################################
2
3
  # test_22_mso_drawing_group.rb
3
4
  #
@@ -16,6 +17,7 @@
16
17
  #
17
18
  #########################################################################
18
19
  require 'helper'
20
+ require 'stringio'
19
21
 
20
22
  class TC_mso_drawing_group < Test::Unit::TestCase
21
23
 
@@ -24,10 +26,7 @@ def test_dummy
24
26
  end
25
27
 
26
28
  def setup
27
- t = Time.now.strftime("%Y%m%d")
28
- path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
29
- @test_file = File.join(Dir.tmpdir, path)
30
- @workbook = WriteExcel.new(@test_file)
29
+ @workbook = WriteExcel.new(StringIO.new)
31
30
  @worksheet1 = @workbook.add_worksheet
32
31
  @worksheet2 = @workbook.add_worksheet
33
32
  @worksheet3 = @workbook.add_worksheet
@@ -35,7 +34,6 @@ def setup
35
34
 
36
35
  def teardown
37
36
  @workbook.close
38
- File.unlink(@test_file) if FileTest.exist?(@test_file)
39
37
  end
40
38
 
41
39
  =begin
@@ -60,7 +58,7 @@ def test_1_time
60
58
 
61
59
 
62
60
  # Test the parameters pass to the worksheets
63
- caption = caption + ' (params)'
61
+ caption += ' (params)'
64
62
  result_ids = []
65
63
  target_ids = [
66
64
  1024, 1, 2, 1025,
@@ -95,7 +93,7 @@ def test_2_times
95
93
 
96
94
 
97
95
  # Test the parameters pass to the worksheets
98
- caption = caption + ' (params)'
96
+ caption += ' (params)'
99
97
  result_ids = []
100
98
  target_ids = [
101
99
  1024, 1, 3, 1026,
@@ -129,7 +127,7 @@ def test_3_times
129
127
 
130
128
 
131
129
  # Test the parameters pass to the worksheets
132
- caption = caption + ' (params)'
130
+ caption += ' (params)'
133
131
  result_ids = []
134
132
  target_ids = [
135
133
  1024, 1, 4, 1027
@@ -163,7 +161,7 @@ def test_1023_times
163
161
 
164
162
 
165
163
  # Test the parameters pass to the worksheets
166
- caption = caption + ' (params)'
164
+ caption += ' (params)'
167
165
  result_ids = []
168
166
  target_ids = [
169
167
  1024, 1, 1024, 2047
@@ -198,7 +196,7 @@ def test_1024_times
198
196
 
199
197
 
200
198
  # Test the parameters pass to the worksheets
201
- caption = caption + ' (params)'
199
+ caption += ' (params)'
202
200
  result_ids = []
203
201
  target_ids = [
204
202
  1024, 1, 1025, 2048
@@ -233,7 +231,7 @@ def test_2048_times
233
231
 
234
232
 
235
233
  # Test the parameters pass to the worksheets
236
- caption = caption + ' (params)'
234
+ caption += ' (params)'
237
235
  result_ids = []
238
236
  target_ids = [
239
237
  1024, 1, 2049, 3072
@@ -273,7 +271,7 @@ def test_2_sheets_1_and_1_times
273
271
 
274
272
 
275
273
  # Test the parameters pass to the worksheets
276
- caption = caption + ' (params)'
274
+ caption += ' (params)'
277
275
  result_ids = []
278
276
  target_ids = [
279
277
  1024, 1, 2, 1025,
@@ -314,7 +312,7 @@ def test_2_sheets_2_and_2_times
314
312
 
315
313
 
316
314
  # Test the parameters pass to the worksheets
317
- caption = caption + ' (params)'
315
+ caption += ' (params)'
318
316
  result_ids = []
319
317
  target_ids = [
320
318
  1024, 1, 3, 1026,
@@ -355,7 +353,7 @@ def test_2_sheets_1023_and_1_times
355
353
 
356
354
 
357
355
  # Test the parameters pass to the worksheets
358
- caption = caption + ' (params)'
356
+ caption += ' (params)'
359
357
  result_ids = []
360
358
  target_ids = [
361
359
  1024, 1, 1024, 2047,
@@ -396,7 +394,7 @@ def test_2_sheets_1023_and_1023_times
396
394
 
397
395
 
398
396
  # Test the parameters pass to the worksheets
399
- caption = caption + ' (params)'
397
+ caption += ' (params)'
400
398
  result_ids = []
401
399
  target_ids = [
402
400
  1024, 1, 1024, 2047,
@@ -438,7 +436,7 @@ def test_2_sheets_1024_and_1024_times
438
436
 
439
437
 
440
438
  # Test the parameters pass to the worksheets
441
- caption = caption + ' (params)'
439
+ caption += ' (params)'
442
440
  result_ids = []
443
441
  target_ids = [
444
442
  1024, 1, 1025, 2048,
@@ -479,7 +477,7 @@ def test_2_sheets_1024_and_1_times
479
477
 
480
478
 
481
479
  # Test the parameters pass to the worksheets
482
- caption = caption + ' (params)'
480
+ caption += ' (params)'
483
481
  result_ids = []
484
482
  target_ids = [
485
483
  1024, 1, 1025, 2048,
@@ -524,7 +522,7 @@ def test_3_sheets_1023_and_1_and_1023_times
524
522
 
525
523
 
526
524
  # Test the parameters pass to the worksheets
527
- caption = caption + ' (params)'
525
+ caption += ' (params)'
528
526
  result_ids = []
529
527
  target_ids = [
530
528
  1024, 1, 1024, 2047,
@@ -570,7 +568,7 @@ def test_3_sheets_1023_and_1023_and_1_times
570
568
 
571
569
 
572
570
  # Test the parameters pass to the worksheets
573
- caption = caption + ' (params)'
571
+ caption += ' (params)'
574
572
  result_ids = []
575
573
  target_ids = [
576
574
  1024, 1, 1024, 2047,
@@ -617,7 +615,7 @@ def test_3_sheets_1024_and_1_and_1024_times
617
615
 
618
616
 
619
617
  # Test the parameters pass to the worksheets
620
- caption = caption + ' (params)'
618
+ caption += ' (params)'
621
619
  result_ids = []
622
620
  target_ids = [
623
621
  1024, 1, 1025, 2048,
@@ -664,7 +662,7 @@ def test_3_sheets_1024_and_1024_and_1_times
664
662
 
665
663
 
666
664
  # Test the parameters pass to the worksheets
667
- caption = caption + ' (params)'
665
+ caption += ' (params)'
668
666
  result_ids = []
669
667
  target_ids = [
670
668
  1024, 1, 1025, 2048,
@@ -721,7 +719,7 @@ def test_3_sheets_1024_and_1024_and_1_times_duplicate
721
719
 
722
720
 
723
721
  # Test the parameters pass to the worksheets
724
- caption = caption + ' (params)'
722
+ caption += ' (params)'
725
723
  result_ids = []
726
724
  target_ids = [
727
725
  1024, 1, 1025, 2048,