writeexcel 0.3.5 → 0.4.0

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 (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,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,66 +1,67 @@
1
- #!/usr/bin/ruby -w
2
-
3
- ###############################################################################
4
- #
5
- # Example of how to use the Spreadsheet::WriteExcel merge_cells() workbook
6
- # method with Unicode strings.
7
- #
8
- #
9
- # reverse('©'), December 2005, John McNamara, jmcnamara@cpan.org
10
- #
11
- # original written in Perl by John McNamara
12
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
13
- #
14
-
15
- require 'writeexcel'
16
-
17
- # Create a new workbook and add a worksheet
18
- workbook = WriteExcel.new('merge6.xls')
19
- worksheet = workbook.add_worksheet
20
-
21
- # Increase the cell size of the merged cells to highlight the formatting.
22
- (2..9).each { |i| worksheet.set_row(i, 36) }
23
- worksheet.set_column('B:D', 25)
24
-
25
- # Format for the merged cells.
26
- format = workbook.add_format(
27
- :border => 6,
28
- :bold => 1,
29
- :color => 'red',
30
- :size => 20,
31
- :valign => 'vcentre',
32
- :align => 'left',
33
- :indent => 1
34
- )
35
-
36
- ###############################################################################
37
- #
38
- # Write an Ascii string.
39
- #
40
-
41
- worksheet.merge_range('B3:D4', 'ASCII: A simple string', format)
42
-
43
- ###############################################################################
44
- #
45
- # Write a UTF-16 Unicode string.
46
- #
47
-
48
- # A phrase in Cyrillic encoded as UTF-16BE.
49
- utf16_str = [
50
- '005500540046002d00310036003a0020' <<
51
- '042d0442043e002004440440043004370430002004' <<
52
- '3d043000200440044304410441043a043e043c0021'
53
- ].pack("H*")
54
-
55
- # Note the extra parameter at the end to indicate UTF-16 encoding.
56
- worksheet.merge_range('B6:D7', utf16_str, format, 1)
57
-
58
- ###############################################################################
59
- #
60
- # Write a UTF-8 Unicode string.
61
- #
62
-
63
- smiley = '☺' # chr 0x263a in perl
64
- worksheet.merge_range('B9:D10', "UTF-8: A Unicode smiley #{smiley}", format)
65
-
66
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # Example of how to use the Spreadsheet::WriteExcel merge_cells() workbook
7
+ # method with Unicode strings.
8
+ #
9
+ #
10
+ # reverse('©'), December 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
+ require 'writeexcel'
17
+
18
+ # Create a new workbook and add a worksheet
19
+ workbook = WriteExcel.new('merge6.xls')
20
+ worksheet = workbook.add_worksheet
21
+
22
+ # Increase the cell size of the merged cells to highlight the formatting.
23
+ (2..9).each { |i| worksheet.set_row(i, 36) }
24
+ worksheet.set_column('B:D', 25)
25
+
26
+ # Format for the merged cells.
27
+ format = workbook.add_format(
28
+ :border => 6,
29
+ :bold => 1,
30
+ :color => 'red',
31
+ :size => 20,
32
+ :valign => 'vcentre',
33
+ :align => 'left',
34
+ :indent => 1
35
+ )
36
+
37
+ ###############################################################################
38
+ #
39
+ # Write an Ascii string.
40
+ #
41
+
42
+ worksheet.merge_range('B3:D4', 'ASCII: A simple string', format)
43
+
44
+ ###############################################################################
45
+ #
46
+ # Write a UTF-16 Unicode string.
47
+ #
48
+
49
+ # A phrase in Cyrillic encoded as UTF-16BE.
50
+ utf16_str = [
51
+ '005500540046002d00310036003a0020' <<
52
+ '042d0442043e002004440440043004370430002004' <<
53
+ '3d043000200440044304410441043a043e043c0021'
54
+ ].pack("H*")
55
+
56
+ # Note the extra parameter at the end to indicate UTF-16 encoding.
57
+ worksheet.merge_range('B6:D7', utf16_str, format, 1)
58
+
59
+ ###############################################################################
60
+ #
61
+ # Write a UTF-8 Unicode string.
62
+ #
63
+
64
+ smiley = '' # chr 0x263a in perl
65
+ worksheet.merge_range('B9:D10', "UTF-8: A Unicode smiley #{smiley}", format)
66
+
67
+ workbook.close
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  #######################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ##############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ##############################################################################
4
5
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  #!/usr/bin/ruby -w
2
3
 
3
4
  ########################################################################
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  #!/usr/bin/ruby -w
2
3
 
3
4
  ######################################################################
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  #######################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ##############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  #!/usr/bin/ruby -w
2
3
 
3
4
  ###############################################################################
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  #######################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  #######################################################################
4
5
  #
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # WriteExcel.
@@ -980,7 +981,8 @@
980
981
  # 6. Ensure that the function is in the above table.
981
982
  #
982
983
  # If you go through steps 1-6 and you still have a problem, mail me.
983
- # Improving performance when working with formulas
984
+ #
985
+ # ===Improving performance when working with formulas
984
986
  #
985
987
  # Writing a large number of formulas with Spreadsheet::WriteExcel can be slow.
986
988
  # This is due to the fact that each formula has to be parsed and with the
@@ -1130,4 +1132,7 @@
1130
1132
  # 12 until another chart with the title set is viewed.
1131
1133
  #
1132
1134
  class WriteExcel < Workbook
1135
+ if RUBY_VERSION < '1.9'
1136
+ $KCODE = 'u'
1137
+ end
1133
1138
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  #
2
3
  # BIFFwriter - An abstract base class for Excel workbooks and worksheets.
3
4
  #
@@ -35,7 +36,7 @@ def initialize
35
36
  # Open a tmp file to store the majority of the Worksheet data. If this fails,
36
37
  # for example due to write permissions, store the data in memory. This can be
37
38
  # slow for large files.
38
- @filehandle = Tempfile.new('spreadsheetwriteexcel')
39
+ @filehandle = Tempfile.new('writeexcel')
39
40
  @filehandle.binmode
40
41
 
41
42
  # failed. store temporary data in memory.
@@ -77,14 +78,14 @@ def set_byte_order
77
78
  #
78
79
  def prepend(*args)
79
80
  d = args.join
80
- d = add_continue(d) if d.length > @limit
81
+ d = add_continue(d) if d.bytesize > @limit
81
82
 
82
- @datasize += d.length
83
+ @datasize += d.bytesize
83
84
  @data = d + @data
84
85
 
85
86
  print "prepend\n" if defined?($debug)
86
87
  print d.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ') + "\n\n" if defined?($debug)
87
- return d
88
+ d
88
89
  end
89
90
 
90
91
  ###############################################################################
@@ -94,20 +95,20 @@ def prepend(*args)
94
95
  # General storage function
95
96
  #
96
97
  def append(*args)
97
- d = args.join
98
+ d = args.collect{ |a| a.dup.force_encoding('ASCII-8BIT') }.join
98
99
  # Add CONTINUE records if necessary
99
- d = add_continue(d) if d.length > @limit
100
+ d = add_continue(d) if d.bytesize > @limit
100
101
  if @using_tmpfile
101
102
  @filehandle.write d
102
- @datasize += d.length
103
+ @datasize += d.bytesize
103
104
  else
104
- @datasize += d.length
105
+ @datasize += d.bytesize
105
106
  @data = @data + d
106
107
  end
107
108
 
108
109
  print "append\n" if defined?($debug)
109
110
  print d.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ') + "\n\n" if defined?($debug)
110
- return d
111
+ d
111
112
  end
112
113
 
113
114
  ###############################################################################
@@ -137,7 +138,7 @@ def get_data
137
138
  end
138
139
 
139
140
  # No data to return
140
- return nil
141
+ nil
141
142
  end
142
143
 
143
144
  ###############################################################################
@@ -212,7 +213,7 @@ def add_continue(data)
212
213
 
213
214
  # in perl
214
215
  # $tmp = substr($data, 0, $limit, "");
215
- if data.length > @limit
216
+ if data.bytesize > @limit
216
217
  tmp = data[0, @limit]
217
218
  data[0, @limit] = ''
218
219
  else
@@ -223,17 +224,15 @@ def add_continue(data)
223
224
  tmp[2, 2] = [@limit-4].pack('v')
224
225
 
225
226
  # Strip out chunks of 2080/8224 bytes +4 for the header.
226
- while (data.length > @limit)
227
+ while (data.bytesize > @limit)
227
228
  header = [record, @limit].pack("vv")
228
- tmp = tmp + header + data[0, @limit]
229
+ tmp += header + data[0, @limit]
229
230
  data[0, @limit] = ''
230
231
  end
231
232
 
232
233
  # Mop up the last of the data
233
- header = [record, data.length].pack("vv")
234
- tmp = tmp + header + data
235
-
236
- return tmp
234
+ header = [record, data.bytesize].pack("vv")
235
+ tmp += header + data
237
236
  end
238
237
 
239
238
  ###############################################################################
@@ -251,14 +250,12 @@ def add_continue(data)
251
250
  # Returns the packed record.
252
251
  #
253
252
  def add_mso_generic(type, version, instance, data, length = nil)
254
- length = length.nil? ? data.length : length
253
+ length = length.nil? ? data.bytesize : length
255
254
 
256
255
  # The header contains version and instance info packed into 2 bytes.
257
256
  header = version | (instance << 4)
258
257
 
259
258
  record = [header, type, length].pack('vvV') + data
260
-
261
- return record
262
259
  end
263
260
 
264
261
  def not_using_tmpfile
@@ -270,4 +267,8 @@ def not_using_tmpfile
270
267
  def clear_data_for_test # :nodoc:
271
268
  @data = ''
272
269
  end
270
+
271
+ def cleanup # :nodoc:
272
+ @filehandle.close(true) if @filehandle
273
+ end
273
274
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  ###############################################################################
2
3
  #
3
4
  # Chart - A writer class for Excel Charts.
@@ -48,7 +49,8 @@
48
49
  # Chart - A writer class for Excel Charts.
49
50
  #
50
51
  class Chart < Worksheet
51
- NonAscii = /[^!"#\$%&'\(\)\*\+,\-\.\/\:\;<=>\?@0-9A-Za-z_\[\\\]^` ~\0\n]/ # :nodoc:
52
+ require 'writeexcel/helper'
53
+ private :convert_to_ascii_if_ascii
52
54
 
53
55
  ###############################################################################
54
56
  #
@@ -639,10 +641,10 @@ def parse_series_formula(formula) # :nodoc:
639
641
  formula = parser.parse_tokens(tokens)
640
642
 
641
643
  # Return formula for a single cell as used by title and series name.
642
- return formula if formula[0] == 0x3A
644
+ return formula if formula.ord == 0x3A
643
645
 
644
646
  # Extract the range from the parse formula.
645
- if formula[0] == 0x3B
647
+ if formula.ord == 0x3B
646
648
  ptg, ext_ref, row_1, row_2, col_1, col_2 = formula.unpack('Cv5')
647
649
 
648
650
  # TODO. Remove high bit on relative references.
@@ -666,16 +668,19 @@ def encode_utf16(str, encoding = 0) # :nodoc:
666
668
  # Return if encoding is set, i.e., string has been manually encoded.
667
669
  #return ( undef, undef ) if $string == 1;
668
670
 
669
- # Handle utf8 strings in perl 5.8.
670
- if string =~ NonAscii
671
+ string = convert_to_ascii_if_ascii(string)
672
+
673
+ # Handle utf8 strings.
674
+ if string.encoding == Encoding::UTF_8
671
675
  string = NKF.nkf('-w16B0 -m0 -W', string)
676
+ string.force_encoding('UTF-16BE')
672
677
  encoding = 1
673
678
  end
674
679
 
675
680
  # Chart strings are limited to 255 characters.
676
681
  limit = encoding != 0 ? 255 * 2 : 255
677
682
 
678
- if string.length >= limit
683
+ if string.bytesize >= limit
679
684
  # truncate the string and raise a warning.
680
685
  string = string[0, limit]
681
686
  end
@@ -733,7 +738,7 @@ def get_color_indices(color) # :nodoc:
733
738
  end
734
739
 
735
740
  rgb = get_color_rbg(index)
736
- return [index, rgb]
741
+ [index, rgb]
737
742
  end
738
743
 
739
744
  ###############################################################################
@@ -1255,7 +1260,9 @@ def store_ai(id, type, formula, format_index = 0) # :nodoc:
1255
1260
  # format_index # Num format index.
1256
1261
  grbit = 0x0000 # Option flags.
1257
1262
 
1258
- formula_length = formula.length
1263
+ formula = convert_to_ascii_if_ascii(formula)
1264
+
1265
+ formula_length = formula.bytesize
1259
1266
  length += formula_length
1260
1267
 
1261
1268
  header = [record, length].pack('vv')
@@ -1264,7 +1271,11 @@ def store_ai(id, type, formula, format_index = 0) # :nodoc:
1264
1271
  data += [grbit].pack('v')
1265
1272
  data += [format_index].pack('v')
1266
1273
  data += [formula_length].pack('v')
1267
- data += formula[0].kind_of?(String) ? formula[0] : formula
1274
+ if formula.kind_of?(Array)
1275
+ data += formula[0].encode('BINARY')
1276
+ else
1277
+ data += formula.encode('BINARY') unless formula.nil?
1278
+ end
1268
1279
 
1269
1280
  print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
1270
1281
  append(header, data)
@@ -1771,7 +1782,7 @@ def store_lineformat(rgb, lns, we, grbit, index) # :nodoc:
1771
1782
 
1772
1783
  print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
1773
1784
  append(header, data)
1774
- end
1785
+ end
1775
1786
 
1776
1787
  ###############################################################################
1777
1788
  #
@@ -1980,12 +1991,14 @@ def store_series(category_count, value_count) # :nodoc:
1980
1991
  # Write the SERIESTEXT chart BIFF record.
1981
1992
  #
1982
1993
  def store_seriestext(str, encoding) # :nodoc:
1994
+ str = convert_to_ascii_if_ascii(str)
1995
+
1983
1996
  record = 0x100D # Record identifier.
1984
1997
  length = 0x0000 # Number of bytes to follow.
1985
1998
  id = 0x0000 # Text id.
1986
1999
  # str # Text.
1987
2000
  # encoding # String encoding.
1988
- cch = str.length # String length.
2001
+ cch = str.bytesize # String length.
1989
2002
 
1990
2003
  encoding ||= 0
1991
2004
 
@@ -1995,7 +2008,7 @@ def store_seriestext(str, encoding) # :nodoc:
1995
2008
  # Change the UTF-16 name from BE to LE
1996
2009
  str = str.unpack('v*').pack('n*') if encoding != 0
1997
2010
 
1998
- length = 4 + str.length
2011
+ length = 4 + str.bytesize
1999
2012
 
2000
2013
  header = [record, length].pack('vv')
2001
2014
  data = [id].pack('v')