writeexcel 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test-suite.yml +26 -0
  3. data/README.rdoc +11 -2
  4. data/lib/writeexcel/biffwriter.rb +2 -1
  5. data/lib/writeexcel/cell_range.rb +1 -0
  6. data/lib/writeexcel/chart.rb +2 -3
  7. data/lib/writeexcel/charts/area.rb +1 -1
  8. data/lib/writeexcel/charts/pie.rb +1 -1
  9. data/lib/writeexcel/charts/scatter.rb +1 -1
  10. data/lib/writeexcel/charts/stock.rb +1 -1
  11. data/lib/writeexcel/col_info.rb +2 -2
  12. data/lib/writeexcel/comments.rb +2 -1
  13. data/lib/writeexcel/convert_date_time.rb +7 -7
  14. data/lib/writeexcel/excelformulaparser.rb +50 -50
  15. data/lib/writeexcel/format.rb +1 -1
  16. data/lib/writeexcel/formula.rb +1 -1
  17. data/lib/writeexcel/helper.rb +3 -3
  18. data/lib/writeexcel/properties.rb +1 -1
  19. data/lib/writeexcel/shared_string_table.rb +5 -5
  20. data/lib/writeexcel/storage_lite.rb +2 -9
  21. data/lib/writeexcel/version.rb +2 -4
  22. data/lib/writeexcel/workbook.rb +14 -25
  23. data/lib/writeexcel/worksheet.rb +73 -56
  24. data/lib/writeexcel/worksheets.rb +1 -2
  25. data/lib/writeexcel.rb +3 -5
  26. data/test/helper.rb +12 -4
  27. data/test/test_00_IEEE_double.rb +1 -1
  28. data/test/test_04_dimensions.rb +6 -6
  29. data/test/test_05_rows.rb +14 -17
  30. data/test/test_06_extsst.rb +8 -11
  31. data/test/test_11_date_time.rb +1 -1
  32. data/test/test_12_date_only.rb +1 -1
  33. data/test/test_13_date_seconds.rb +1 -1
  34. data/test/test_21_escher.rb +5 -5
  35. data/test/test_22_mso_drawing_group.rb +37 -40
  36. data/test/test_23_note.rb +5 -5
  37. data/test/test_24_txo.rb +5 -5
  38. data/test/test_25_position_object.rb +5 -5
  39. data/test/test_26_autofilter.rb +1 -1
  40. data/test/test_27_autofilter.rb +1 -1
  41. data/test/test_28_autofilter.rb +1 -1
  42. data/test/test_29_process_jpg.rb +1 -43
  43. data/test/test_30_validation_dval.rb +5 -5
  44. data/test/test_31_validation_dv_strings.rb +8 -8
  45. data/test/test_32_validation_dv_formula.rb +5 -5
  46. data/test/test_40_property_types.rb +1 -1
  47. data/test/test_41_properties.rb +1 -1
  48. data/test/test_42_set_properties.rb +30 -37
  49. data/test/test_50_name_stored.rb +1 -19
  50. data/test/test_51_name_print_area.rb +3 -13
  51. data/test/test_52_name_print_titles.rb +3 -21
  52. data/test/test_53_autofilter.rb +1 -5
  53. data/test/test_60_chart_generic.rb +3 -3
  54. data/test/test_61_chart_subclasses.rb +2 -1
  55. data/test/test_62_chart_formats.rb +9 -21
  56. data/test/test_63_chart_area_formats.rb +1 -1
  57. data/test/test_compatibility.rb +1 -1
  58. data/test/test_example_match.rb +835 -835
  59. data/test/test_format.rb +1 -114
  60. data/test/test_formula.rb +1 -1
  61. data/test/test_properties.rb +1 -2
  62. data/test/test_storage_lite.rb +2 -2
  63. data/test/test_workbook.rb +1 -66
  64. data/test/test_worksheet.rb +1 -18
  65. data/test/test_write_formula_does_not_change_formula_string.rb +1 -1
  66. data/writeexcel.gemspec +6 -3
  67. metadata +24 -21
  68. data/test/test_01_add_worksheet.rb +0 -43
  69. data/test/test_02_merge_formats.rb +0 -49
  70. data/test/test_biff.rb +0 -71
  71. data/test/test_big_workbook.rb +0 -17
  72. data/test/test_ole.rb +0 -102
@@ -55,8 +55,6 @@ class OLEStorageLite #:nodoc:
55
55
  end
56
56
  done << no
57
57
 
58
- rootblock = info[:root_start]
59
-
60
58
  #1. Get Information about itself
61
59
  pps = _getNthPps(no, info, data)
62
60
 
@@ -76,7 +74,6 @@ class OLEStorageLite #:nodoc:
76
74
  private :_getPpsTree
77
75
 
78
76
  def _getPpsSearch(no, info, name, data, icase, done = nil)
79
- rootblock = info[:root_start]
80
77
  #1. Check it self
81
78
  if done
82
79
  return [] if done.include?(no)
@@ -589,7 +586,6 @@ class OLEStorageLitePPSRoot < OLEStorageLitePPS #:nodoc:
589
586
  rh_info[:fileh] = sFile.binmode
590
587
  end
591
588
 
592
- iBlk = 0
593
589
  #1. Make an array of PPS (for Save)
594
590
  aList=[]
595
591
  if bNoAs
@@ -728,7 +724,6 @@ class OLEStorageLitePPSRoot < OLEStorageLitePPS #:nodoc:
728
724
  private :_saveHeader
729
725
 
730
726
  def _saveBigData(iStBlk, aList, rh_info)
731
- iRes = 0
732
727
  file = rh_info[:fileh]
733
728
 
734
729
  #1.Write Big (ge 0x1000) Data into Block
@@ -810,7 +805,7 @@ class OLEStorageLitePPSRoot < OLEStorageLitePPS #:nodoc:
810
805
  aPrev = aWk[0, iPos]
811
806
  aWk[0..iPos-1] = []
812
807
  aNext = aWk[1, iCnt - iPos - 1]
813
- aWk[1..(1 + iCnt - iPos -1 -1)] = []
808
+ aWk[1..(1 + iCnt - iPos - 1 - 1)] = []
814
809
  pps_array[iPos].prev_pps = _savePpsSetPnt(aPrev, aList, rh_info)
815
810
  pps_array[iPos].next_pps = _savePpsSetPnt(aNext, aList, rh_info)
816
811
  pps_array[iPos].dir_pps = _savePpsSetPnt(pps_array[iPos].child, aList, rh_info)
@@ -834,12 +829,10 @@ class OLEStorageLitePPSRoot < OLEStorageLitePPS #:nodoc:
834
829
  return pps_array[0].no
835
830
  #1.3 Array
836
831
  else
837
- iCnt = pps_array.size
838
832
  #1.3.1 Define Center
839
833
  iPos = 0 #int($iCnt/ 2); #$iCnt
840
834
 
841
835
  aWk = pps_array.dup
842
- aPrev = aWk[1, 1]
843
836
  aWk[1..1] = []
844
837
  aNext = aWk[1..aWk.size] #, $iCnt - $iPos -1);
845
838
  pps_array[iPos].prev_pps = _savePpsSetPnt2(pps_array, aList, rh_info)
@@ -975,7 +968,7 @@ class OLEStorageLitePPSFile < OLEStorageLitePPS #:nodoc:
975
968
  @pps_file.binmode
976
969
  end
977
970
 
978
- def append (data)
971
+ def append(data)
979
972
  return if data.nil?
980
973
  if @pps_file
981
974
  @pps_file << data
@@ -1,5 +1,3 @@
1
- require 'writeexcel'
2
-
3
- class WriteExcel < Workbook
4
- VERSION = "1.0.5"
1
+ module Writeexcel
2
+ VERSION = "1.0.7"
5
3
  end
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
  ###############################################################################
3
4
  #
4
5
  # Workbook - A writer class for Excel Workbooks.
@@ -13,20 +14,9 @@
13
14
  #
14
15
  require 'nkf'
15
16
  require 'forwardable'
16
- require 'writeexcel/biffwriter'
17
- require 'writeexcel/worksheet'
18
- require 'writeexcel/chart'
19
- require 'writeexcel/format'
20
- require 'writeexcel/formula'
21
- require 'writeexcel/olewriter'
22
- require 'writeexcel/storage_lite'
23
- require 'writeexcel/compatibility'
24
17
  require 'writeexcel/shared_string_table'
25
- require 'writeexcel/worksheets'
26
18
 
27
19
  class Workbook < BIFFWriter
28
- require 'writeexcel/properties'
29
- require 'writeexcel/helper'
30
20
 
31
21
  extend Forwardable
32
22
 
@@ -115,6 +105,7 @@ class Workbook < BIFFWriter
115
105
  @localtime = Time.now
116
106
 
117
107
  @defined_names = []
108
+ @fileclosed = nil
118
109
 
119
110
  setup_built_in_formats(default_formats)
120
111
 
@@ -652,7 +643,6 @@ class Workbook < BIFFWriter
652
643
  #
653
644
  def define_name(name, formula, encoding = 0)
654
645
  sheet_index = 0
655
- full_name = name.downcase
656
646
 
657
647
  if name =~ /^(.*)!(.*)$/
658
648
  sheetname = $1
@@ -1266,7 +1256,7 @@ class Workbook < BIFFWriter
1266
1256
  # Add the length of the MSODRAWINGGROUP records including an extra 4 bytes
1267
1257
  # for any CONTINUE headers. See add_mso_drawing_group_continue().
1268
1258
  mso_size = @mso_size
1269
- mso_size += 4 * Integer((mso_size -1) / Float(@limit))
1259
+ mso_size += 4 * Integer((mso_size - 1) / Float(@limit))
1270
1260
  offset += mso_size
1271
1261
 
1272
1262
  @worksheets.each do |sheet|
@@ -1374,7 +1364,7 @@ class Workbook < BIFFWriter
1374
1364
  image_id += 1
1375
1365
  else
1376
1366
  # We've processed this file already.
1377
- index = images_seen[image.filename] -1
1367
+ index = images_seen[image.filename] - 1
1378
1368
 
1379
1369
  # Increase image reference count.
1380
1370
  image_data[index].ref_count += 1
@@ -2053,7 +2043,6 @@ class Workbook < BIFFWriter
2053
2043
  def store_shared_strings #:nodoc:
2054
2044
  record = 0x00FC # Record identifier
2055
2045
  length = 0x0008 # Number of bytes to follow
2056
- total = 0x0000
2057
2046
 
2058
2047
  # Iterate through the strings to calculate the CONTINUE block sizes
2059
2048
  continue_limit = 8208
@@ -2136,10 +2125,10 @@ class Workbook < BIFFWriter
2136
2125
  append(tmp)
2137
2126
 
2138
2127
  # The remainder will be written in the next block(s)
2139
- string = string[space_remaining .. string.length-1]
2128
+ string = string[space_remaining .. string.length - 1]
2140
2129
 
2141
2130
  # Reduce the current block length by the amount written
2142
- block_length -= continue_limit -continue -align
2131
+ block_length -= continue_limit - continue - align
2143
2132
 
2144
2133
  # If the current string was split then the next CONTINUE block
2145
2134
  # should have the string continue flag (grbit) set unless the
@@ -2152,7 +2141,7 @@ class Workbook < BIFFWriter
2152
2141
  end
2153
2142
  else
2154
2143
  # Not enough space to start the string in the current block
2155
- block_length -= continue_limit -space_remaining -continue
2144
+ block_length -= continue_limit - space_remaining - continue
2156
2145
  continue = 0
2157
2146
  end
2158
2147
 
@@ -2206,7 +2195,7 @@ class Workbook < BIFFWriter
2206
2195
  bucket_size = 1 + Integer(unique_strings / 128.0)
2207
2196
  end
2208
2197
 
2209
- buckets = Integer((unique_strings + bucket_size -1) / Float(bucket_size))
2198
+ buckets = Integer((unique_strings + bucket_size - 1) / Float(bucket_size))
2210
2199
 
2211
2200
  @extsst_buckets = buckets
2212
2201
  @extsst_bucket_size = bucket_size
@@ -2278,7 +2267,7 @@ class Workbook < BIFFWriter
2278
2267
  # Case 3: > 2*8224 bytes 2 MSODRAWINGGROUP + n CONTINUE
2279
2268
  #
2280
2269
  def add_mso_drawing_group_continue(data) #:nodoc:
2281
- limit = 8228 -4
2270
+ limit = 8228 - 4
2282
2271
  mso_group = 0x00EB # Record identifier
2283
2272
  continue = 0x003C # Record identifier
2284
2273
  block_count = 1
@@ -2334,7 +2323,7 @@ class Workbook < BIFFWriter
2334
2323
  version = 15
2335
2324
  instance = 0
2336
2325
  data = ''
2337
- length = @mso_size -12 # -4 (biff header) -8 (for this).
2326
+ length = @mso_size - 12 # -4 (biff header) -8 (for this).
2338
2327
 
2339
2328
  add_mso_generic(type, version, instance, data, length)
2340
2329
  end
@@ -2372,7 +2361,7 @@ class Workbook < BIFFWriter
2372
2361
  version = 15
2373
2362
  instance = @images_data.size # Number of images.
2374
2363
  data = ''
2375
- length = @images_size +8 *instance
2364
+ length = @images_size + 8 * instance
2376
2365
 
2377
2366
  add_mso_generic(type, version, instance, data, length)
2378
2367
  end
@@ -2399,12 +2388,12 @@ class Workbook < BIFFWriter
2399
2388
  type = 0xF007
2400
2389
  version = 2
2401
2390
  instance = image_type
2402
- length = size +61
2391
+ length = size + 61
2403
2392
  data = [image_type].pack('C') + # Win32
2404
2393
  [image_type].pack('C') + # Mac
2405
2394
  [checksum1].pack('H*') + # Uid checksum
2406
2395
  [0xFF].pack('v') + # Tag
2407
- [size +25].pack('V') + # Next Blip size
2396
+ [size + 25].pack('V') + # Next Blip size
2408
2397
  [ref_count].pack('V') + # Image ref count
2409
2398
  [0x00000000].pack('V') + # File offset
2410
2399
  [0x00].pack('C') + # Usage
@@ -2430,7 +2419,7 @@ class Workbook < BIFFWriter
2430
2419
 
2431
2420
  type = 0xF018 + image_type
2432
2421
  version = 0x0000
2433
- length = size +17
2422
+ length = size + 17
2434
2423
  data = [checksum1].pack('H*') + # Uid checksum
2435
2424
  [0xFF].pack('C') + # Tag
2436
2425
  image_data # Image
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
  ###############################################################################
3
4
  #
4
5
  # Worksheet - A writer class for Excel Worksheets.
@@ -102,6 +103,7 @@ class Worksheet < BIFFWriter
102
103
  @title_range = TitleRange.new(self)
103
104
  @print_range = PrintRange.new(self)
104
105
 
106
+ @print_headers = 0
105
107
  @print_gridlines = 1
106
108
  @screen_gridlines = 1
107
109
 
@@ -154,6 +156,18 @@ class Worksheet < BIFFWriter
154
156
 
155
157
  @table = []
156
158
  @row_data = {}
159
+ @header = ''
160
+ @header_encoding = nil
161
+ @footer = ''
162
+ @footer_encoding = nil
163
+ @hidden = nil
164
+ @selected = nil
165
+ @protect = nil
166
+ @hcenter = nil
167
+ @vcenter = nil
168
+ @display_arabic = nil
169
+ @frozen = nil
170
+ @hide_zeros = nil
157
171
  end
158
172
 
159
173
  #
@@ -352,8 +366,8 @@ class Worksheet < BIFFWriter
352
366
  # worksheet2.activate
353
367
  # worksheet1.hide
354
368
  #
355
- def hide
356
- @hidden = true
369
+ def hide(hidden = :hidden)
370
+ @hidden = hidden
357
371
 
358
372
  # A hidden worksheet shouldn't be active or selected.
359
373
  @selected = false
@@ -536,7 +550,7 @@ class Worksheet < BIFFWriter
536
550
  # not be obtained exactly due to rounding in Excel.
537
551
  #
538
552
  if height
539
- miyRw = height *20
553
+ miyRw = height * 20
540
554
  else
541
555
  miyRw = 0xff # The default row height
542
556
  height = 0
@@ -672,8 +686,11 @@ class Worksheet < BIFFWriter
672
686
  #
673
687
  def set_column(*args)
674
688
  # Check for a cell reference in A1 notation and substitute row and column
675
- if args[0] =~ /^\D/
676
- row1, firstcol, row2, lastcol, *data = substitute_cellref(*args)
689
+ if args[0].respond_to?(:match) && args[0] =~ /^\D/
690
+ array = substitute_cellref(*args)
691
+ firstcol = array[1]
692
+ lastcol = array[3]
693
+ *data = array[4, array.length - 4]
677
694
  else
678
695
  firstcol, lastcol, *data = args
679
696
  end
@@ -959,11 +976,11 @@ class Worksheet < BIFFWriter
959
976
  format = args[5]
960
977
  encoding = args[6] ? 1 : 0
961
978
 
962
- merge_range_core(rwFirst, colFirst, rwLast, colLast, string, format, encoding) do |rwFirst, colFirst, string, format, encoding|
963
- if encoding != 0
964
- write_utf16be_string(rwFirst, colFirst, string, format)
979
+ merge_range_core(rwFirst, colFirst, rwLast, colLast, string, format, encoding) do |_rwFirst, _colFirst, _string, _format, _encoding|
980
+ if _encoding != 0
981
+ write_utf16be_string(_rwFirst, _colFirst, _string, _format)
965
982
  else
966
- write(rwFirst, colFirst, string, format)
983
+ write(_rwFirst, _colFirst, _string, _format)
967
984
  end
968
985
  end
969
986
  end
@@ -990,8 +1007,8 @@ class Worksheet < BIFFWriter
990
1007
  format = args[5]
991
1008
  encoding = nil
992
1009
 
993
- merge_range_core(rwFirst, colFirst, rwLast, colLast, string, format, encoding) do |rwFirst, colFirst, string, format, encoding|
994
- write_date_time(rwFirst, colFirst, string, format)
1010
+ merge_range_core(rwFirst, colFirst, rwLast, colLast, string, format, encoding) do |_rwFirst, _colFirst, _string, _format, _encoding|
1011
+ write_date_time(_rwFirst, _colFirst, _string, _format)
995
1012
  end
996
1013
  end
997
1014
 
@@ -1211,7 +1228,7 @@ class Worksheet < BIFFWriter
1211
1228
 
1212
1229
  # Check for a column reference in A1 notation and substitute.
1213
1230
  # Convert col ref to a cell ref and then to a col number.
1214
- dummy, col = substitute_cellref("#{col}1") if col =~ /^\D/
1231
+ col = substitute_cellref("#{col}1")[1] if col.to_s =~ /^\D/
1215
1232
 
1216
1233
  # Reject column if it is outside filter range.
1217
1234
  unless @filter_area.inside?(col)
@@ -1615,8 +1632,10 @@ class Worksheet < BIFFWriter
1615
1632
  #
1616
1633
  def repeat_columns(*args)
1617
1634
  # Check for a cell reference in A1 notation and substitute row and column
1618
- if args[0] =~ /^\D/
1619
- row1, firstcol, row2, lastcol = substitute_cellref(*args)
1635
+ if args[0].to_s =~ /^\D/
1636
+ array = substitute_cellref(*args)
1637
+ firstcol = array[1]
1638
+ lastcol = array[3]
1620
1639
  else
1621
1640
  firstcol, lastcol = args
1622
1641
  end
@@ -2209,10 +2228,8 @@ class Worksheet < BIFFWriter
2209
2228
  # Check for a cell reference in A1 notation and substitute row and column
2210
2229
  args = row_col_notation(args)
2211
2230
 
2212
- token = args[2]
2213
-
2214
2231
  # Handle undefs as blanks
2215
- token ||= ''
2232
+ token = args[2] || ''
2216
2233
 
2217
2234
  # First try user defined matches.
2218
2235
  @write_match.each do |aref|
@@ -2223,7 +2240,7 @@ class Worksheet < BIFFWriter
2223
2240
  match = eval("#{sub} self, args")
2224
2241
  return match if match
2225
2242
  end
2226
- end
2243
+ end if token.respond_to?(:match)
2227
2244
 
2228
2245
  # Match an array ref.
2229
2246
  if token.respond_to?(:to_ary)
@@ -2231,16 +2248,16 @@ class Worksheet < BIFFWriter
2231
2248
  elsif token.respond_to?(:coerce) # Numeric
2232
2249
  write_number(*args)
2233
2250
  # Match http, https or ftp URL
2234
- elsif token =~ %r|^[fh]tt?ps?://|
2251
+ elsif token.respond_to?(:match) && token =~ %r|^[fh]tt?ps?://|
2235
2252
  write_url(*args)
2236
2253
  # Match mailto:
2237
- elsif token =~ %r|^mailto:|
2254
+ elsif token.respond_to?(:match) && token =~ %r|^mailto:|
2238
2255
  write_url(*args)
2239
2256
  # Match internal or external sheet link
2240
- elsif token =~ %r!^(?:in|ex)ternal:!
2257
+ elsif token.respond_to?(:match) && token =~ %r!^(?:in|ex)ternal:!
2241
2258
  write_url(*args)
2242
2259
  # Match formula
2243
- elsif token =~ /^=/
2260
+ elsif token.respond_to?(:match) && token =~ /^=/
2244
2261
  write_formula(*args)
2245
2262
  # Match blank
2246
2263
  elsif token == ''
@@ -3495,7 +3512,8 @@ class Worksheet < BIFFWriter
3495
3512
 
3496
3513
  return -1 if args.size < 3 # Check the number of args
3497
3514
 
3498
- row, col, comment, params = args
3515
+ row, col = args
3516
+ params = args[3]
3499
3517
 
3500
3518
  # Check for pairs of optional arguments, i.e. an odd number of args.
3501
3519
  # raise "Uneven number of additional arguments" if args.size % 2 == 0
@@ -4308,7 +4326,7 @@ class Worksheet < BIFFWriter
4308
4326
  end
4309
4327
 
4310
4328
  def hidden? # :nodoc:
4311
- @hidden
4329
+ @hidden == :hidden
4312
4330
  end
4313
4331
 
4314
4332
  def hidden=(val) # :nodoc:
@@ -4457,10 +4475,10 @@ class Worksheet < BIFFWriter
4457
4475
  y2 = 256.0 * height / size_row(row_end)
4458
4476
 
4459
4477
  # Simulate ceil() without calling POSIX::ceil().
4460
- x1 = (x1 +0.5).to_i
4461
- y1 = (y1 +0.5).to_i
4462
- x2 = (x2 +0.5).to_i
4463
- y2 = (y2 +0.5).to_i
4478
+ x1 = (x1 + 0.5).to_i
4479
+ y1 = (y1 + 0.5).to_i
4480
+ x2 = (x2 + 0.5).to_i
4481
+ y2 = (y2 + 0.5).to_i
4464
4482
 
4465
4483
  [
4466
4484
  col_start, x1,
@@ -4615,7 +4633,7 @@ class Worksheet < BIFFWriter
4615
4633
  drawings_saved += 1
4616
4634
 
4617
4635
  # For each sheet start the spids at the next 1024 interval.
4618
- max_spid = 1024 * (1 + Integer((max_spid -1)/1024.0))
4636
+ max_spid = 1024 * (1 + Integer((max_spid - 1) / 1024.0))
4619
4637
  start_spid = max_spid
4620
4638
 
4621
4639
  # Max spid for each sheet and eventually for the workbook.
@@ -4626,7 +4644,7 @@ class Worksheet < BIFFWriter
4626
4644
  push_cluster(num_shapes, drawings_saved, clusters)
4627
4645
 
4628
4646
  # Pass calculated values back to the worksheet
4629
- @object_ids = ObjectIds.new(start_spid, drawings_saved, num_shapes, max_spid -1)
4647
+ @object_ids = ObjectIds.new(start_spid, drawings_saved, num_shapes, max_spid - 1)
4630
4648
 
4631
4649
  [mso_size, drawings_saved, max_spid, start_spid]
4632
4650
  end
@@ -4666,7 +4684,7 @@ class Worksheet < BIFFWriter
4666
4684
  def set_header_footer_common(type, string, margin, encoding) # :nodoc:
4667
4685
  ruby_19 { string = convert_to_ascii_if_ascii(string) }
4668
4686
 
4669
- limit = encoding != 0 ? 255 *2 : 255
4687
+ limit = encoding != 0 ? 255 * 2 : 255
4670
4688
 
4671
4689
  # Handle utf8 strings
4672
4690
  if is_utf8?(string)
@@ -4821,7 +4839,7 @@ class Worksheet < BIFFWriter
4821
4839
  # Special handling of "Top" filter expressions.
4822
4840
  if tokens[0] =~ /^top|bottom$/i
4823
4841
  value = tokens[1]
4824
- if (value =~ /\D/ or value.to_i < 1 or value.to_i > 500)
4842
+ if (value.to_s =~ /\D/ or value.to_i < 1 or value.to_i > 500)
4825
4843
  raise "The value '#{value}' in expression '#{expression}' " +
4826
4844
  "must be in the range 1 to 500"
4827
4845
  end
@@ -4850,7 +4868,7 @@ class Worksheet < BIFFWriter
4850
4868
  end
4851
4869
 
4852
4870
  # Special handling for Blanks/NonBlanks.
4853
- if (token =~ /^blanks|nonblanks$/i)
4871
+ if (token.to_s =~ /^blanks|nonblanks$/i)
4854
4872
  # Only allow Equals or NotEqual in this context.
4855
4873
  if (operator != 2 and operator != 5)
4856
4874
  raise "The operator '#{tokens[1]}' in expression '#{expression}' " +
@@ -4876,7 +4894,7 @@ class Worksheet < BIFFWriter
4876
4894
 
4877
4895
  # if the string token contains an Excel match character then change the
4878
4896
  # operator type to indicate a non "simple" equality.
4879
- if (operator == 2 and token =~ /[*?]/)
4897
+ if (operator == 2 and token.to_s =~ /[*?]/)
4880
4898
  operator = 22
4881
4899
  end
4882
4900
 
@@ -4936,31 +4954,27 @@ class Worksheet < BIFFWriter
4936
4954
  def substitute_cellref(cell, *args) #:nodoc:
4937
4955
  return [cell, *args] if cell.respond_to?(:coerce) # Numeric
4938
4956
 
4939
- cell.upcase!
4957
+ normalized_cell = cell.upcase
4940
4958
 
4959
+ case normalized_cell
4941
4960
  # Convert a column range: 'A:A' or 'B:G'.
4942
4961
  # A range such as A:A is equivalent to A1:65536, so add rows as required
4943
- if cell =~ /\$?([A-I]?[A-Z]):\$?([A-I]?[A-Z])/
4944
- row1, col1 = cell_to_rowcol($1 +'1')
4945
- row2, col2 = cell_to_rowcol($2 +'65536')
4962
+ when /\$?([A-I]?[A-Z]):\$?([A-I]?[A-Z])/
4963
+ row1, col1 = cell_to_rowcol($1 + '1')
4964
+ row2, col2 = cell_to_rowcol($2 + '65536')
4946
4965
  return [row1, col1, row2, col2, *args]
4947
- end
4948
-
4949
4966
  # Convert a cell range: 'A1:B7'
4950
- if cell =~ /\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/
4967
+ when /\$?([A-I]?[A-Z]\$?\d+):\$?([A-I]?[A-Z]\$?\d+)/
4951
4968
  row1, col1 = cell_to_rowcol($1)
4952
4969
  row2, col2 = cell_to_rowcol($2)
4953
4970
  return [row1, col1, row2, col2, *args]
4954
- end
4955
-
4956
4971
  # Convert a cell reference: 'A1' or 'AD2000'
4957
- if (cell =~ /\$?([A-I]?[A-Z]\$?\d+)/)
4972
+ when /\$?([A-I]?[A-Z]\$?\d+)/
4958
4973
  row1, col1 = cell_to_rowcol($1)
4959
4974
  return [row1, col1, *args]
4960
-
4975
+ else
4976
+ raise("Unknown cell reference #{normalized_cell}")
4961
4977
  end
4962
-
4963
- raise("Unknown cell reference #{cell}")
4964
4978
  end
4965
4979
 
4966
4980
  #
@@ -5177,8 +5191,8 @@ class Worksheet < BIFFWriter
5177
5191
  # Convert an Ascii URL type and to a null terminated wchar string.
5178
5192
  if encoding == 0
5179
5193
  url =
5180
- ruby_18 { url + "\0" } ||
5181
- ruby_19 { url.force_encoding('BINARY') + "\0".force_encoding('BINARY') }
5194
+ ruby_18 { url.dup + "\0" } ||
5195
+ ruby_19 { url.dup.force_encoding('BINARY') + "\0" }
5182
5196
  url = url.unpack('c*').pack('v*')
5183
5197
  end
5184
5198
 
@@ -5266,12 +5280,12 @@ class Worksheet < BIFFWriter
5266
5280
  end
5267
5281
 
5268
5282
  def sheetname_from_url(url)
5269
- sheetname, cell = url.split('!')
5283
+ sheetname = url.split('!')[0]
5270
5284
  sheetname
5271
5285
  end
5272
5286
 
5273
5287
  def cell_from_url(url)
5274
- sheetname, cell = url.split('!')
5288
+ cell = url.split('!')[1]
5275
5289
  cell
5276
5290
  end
5277
5291
 
@@ -6368,9 +6382,9 @@ class Worksheet < BIFFWriter
6368
6382
 
6369
6383
  # The relationship is different for user units less than 1.
6370
6384
  if width < 1
6371
- (width *12).to_i
6385
+ (width * 12).to_i
6372
6386
  else
6373
- (width *7 +5 ).to_i
6387
+ (width * 7 + 5 ).to_i
6374
6388
  end
6375
6389
  else
6376
6390
  64
@@ -6427,7 +6441,7 @@ class Worksheet < BIFFWriter
6427
6441
 
6428
6442
  col1.upto(col2) do |i|
6429
6443
  # Reverse order since records are being pre-pended.
6430
- col = col2 -i
6444
+ col = col2 - i
6431
6445
 
6432
6446
  # Skip if column doesn't have an active filter.
6433
6447
  next unless @filter_cols[col]
@@ -6546,7 +6560,7 @@ class Worksheet < BIFFWriter
6546
6560
  # Handle utf8 strings
6547
6561
  if is_utf8?(string)
6548
6562
  string = utf8_to_16be(string)
6549
- encodign = 1
6563
+ encoding = 1
6550
6564
  end
6551
6565
 
6552
6566
  string =
@@ -6950,7 +6964,10 @@ class Worksheet < BIFFWriter
6950
6964
 
6951
6965
  # Check for a cell reference in A1 notation and substitute row and column
6952
6966
  def row_col_notation(args) # :nodoc:
6953
- if args[0] =~ /^\D/
6967
+ # ruby 3.2 no longer handles =~ for various types
6968
+ return args unless args[0].respond_to?(:=~)
6969
+
6970
+ if args[0].respond_to?(:match) && args[0] =~ /^\D/
6954
6971
  substitute_cellref(*args)
6955
6972
  else
6956
6973
  args
@@ -1,6 +1,4 @@
1
1
  class Workbook < BIFFWriter
2
- require 'writeexcel/properties'
3
- require 'writeexcel/helper'
4
2
 
5
3
  class Worksheets < Array
6
4
  attr_accessor :activesheet
@@ -8,6 +6,7 @@ class Workbook < BIFFWriter
8
6
 
9
7
  def initialize
10
8
  @activesheet = nil
9
+ @firstsheet = nil
11
10
  end
12
11
 
13
12
  def activesheet_index
data/lib/writeexcel.rb CHANGED
@@ -10,12 +10,13 @@
10
10
  # original written in Perl by John McNamara
11
11
  # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
12
12
  #
13
+ require 'writeexcel/version'
13
14
  require 'writeexcel/biffwriter'
14
15
  require 'writeexcel/olewriter'
15
16
  require 'writeexcel/formula'
16
17
  require 'writeexcel/format'
17
- require 'writeexcel/worksheet'
18
- require "writeexcel/workbook"
18
+ require 'writeexcel/worksheets'
19
+ require 'writeexcel/workbook'
19
20
  require 'writeexcel/chart'
20
21
  require 'writeexcel/charts/area'
21
22
  require 'writeexcel/charts/bar'
@@ -1153,7 +1154,4 @@ require 'writeexcel/debug_info'
1153
1154
  # 12 until another chart with the title set is viewed.
1154
1155
  #
1155
1156
  class WriteExcel < Workbook
1156
- if RUBY_VERSION < '1.9'
1157
- $KCODE = 'u'
1158
- end
1159
1157
  end
data/test/helper.rb CHANGED
@@ -1,14 +1,22 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'simplecov'
3
- require 'test/unit'
2
+ # frozen_string_literal: true
4
3
 
5
- SimpleCov.start
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ warn e.message
10
+ warn "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'minitest/autorun'
6
14
 
7
15
  $LOAD_PATH.unshift(File.dirname(__FILE__))
8
16
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
17
  require 'writeexcel'
10
18
 
11
- class Test::Unit::TestCase
19
+ class Minitest::Test
12
20
  ###############################################################################
13
21
  #
14
22
  # Unpack the binary data into a format suitable for printing in tests.
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'helper'
3
3
 
4
- class TC_BIFFWriter < Test::Unit::TestCase
4
+ class TC_BIFFWriter < Minitest::Test
5
5
 
6
6
  def test_IEEE_double
7
7
  teststr = [1.2345].pack("d")
@@ -14,7 +14,7 @@
14
14
  require 'helper'
15
15
  require 'stringio'
16
16
 
17
- class TC_dimensions < Test::Unit::TestCase
17
+ class TC_dimensions < Minitest::Test
18
18
 
19
19
  def setup
20
20
  @workbook = WriteExcel.new(StringIO.new)
@@ -25,11 +25,11 @@ class TC_dimensions < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  def teardown
28
- if @workbook.instance_variable_get(:@filehandle)
29
- @workbook.instance_variable_get(:@filehandle).close(true)
28
+ if @workbook.instance_variable_get("@filehandle")
29
+ @workbook.instance_variable_get("@filehandle").close(true)
30
30
  end
31
- if @worksheet.instance_variable_get(:@filehandle)
32
- @worksheet.instance_variable_get(:@filehandle).close(true)
31
+ if @worksheet.instance_variable_get("@filehandle")
32
+ @worksheet.instance_variable_get("@filehandle").close(true)
33
33
  end
34
34
  end
35
35
 
@@ -386,7 +386,7 @@ class TC_dimensions < Test::Unit::TestCase
386
386
  end
387
387
 
388
388
  def test_merge_range
389
- formula = @worksheet.__send__("store_formula", '=A1 * 3 + 50')
389
+ @worksheet.__send__("store_formula", '=A1 * 3 + 50')
390
390
  @worksheet.merge_range('C6:E8', 'Test', @format)
391
391
 
392
392
  data = @worksheet.__send__("store_dimensions")