writeexcel 0.4.0 → 0.4.1

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.
@@ -11,9 +11,10 @@
11
11
  # original written in Perl by John McNamara
12
12
  # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
13
13
  #
14
+ require 'writeexcel/biffwriter'
14
15
  require 'writeexcel/format'
15
16
  require 'writeexcel/formula'
16
- require 'writeexcel/workbook'
17
+ require 'writeexcel/compatibility'
17
18
 
18
19
  class MaxSizeError < StandardError #:nodoc:
19
20
  end
@@ -577,7 +578,7 @@ def set_row(row, height = nil, format = nil, hidden = 0, level = 0, collapsed =
577
578
  return -2 if check_dimensions(row, 0, 0, 1) != 0
578
579
 
579
580
  # Check for a format object
580
- if format.kind_of?(Format)
581
+ if format.respond_to?(:xf_index)
581
582
  ixfe = format.xf_index
582
583
  else
583
584
  ixfe = 0x0F
@@ -621,7 +622,6 @@ def set_row(row, height = nil, format = nil, hidden = 0, level = 0, collapsed =
621
622
  if @compatibility != 0
622
623
  @row_data[row] = header + data
623
624
  else
624
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
625
625
  append(header, data)
626
626
  end
627
627
 
@@ -1012,7 +1012,7 @@ def merge_range(*args)
1012
1012
  args = substitute_cellref(*args)
1013
1013
  end
1014
1014
  raise "Incorrect number of arguments" if args.size != 6 and args.size != 7
1015
- raise "Format argument is not a format object" unless args[5].kind_of?(Format)
1015
+ raise "Format argument is not a format object" unless args[5].respond_to?(:xf_index)
1016
1016
 
1017
1017
  rwFirst = args[0]
1018
1018
  colFirst = args[1]
@@ -1128,8 +1128,8 @@ def hide_zero
1128
1128
  #
1129
1129
  # See the tab_colors.rb program in the examples directory of the distro.
1130
1130
  #
1131
- def set_tab_color(colour)
1132
- color = Format._get_color(colour)
1131
+ def set_tab_color(color)
1132
+ color = Colors.new.get_color(color)
1133
1133
  color = 0 if color == 0x7FFF # Default color.
1134
1134
  @tab_color = color
1135
1135
  end
@@ -1657,24 +1657,7 @@ def set_margin_bottom(margin = 1.00)
1657
1657
  # distribution.
1658
1658
  #
1659
1659
  def set_header(string = '', margin = 0.50, encoding = 0)
1660
- string = convert_to_ascii_if_ascii(string)
1661
-
1662
- limit = encoding != 0 ? 255 *2 : 255
1663
-
1664
- # Handle utf8 strings
1665
- if string.encoding == Encoding::UTF_8
1666
- string = string.encode('UTF-16BE')
1667
- encoding = 1
1668
- end
1669
-
1670
- if string.bytesize >= limit
1671
- # carp 'Header string must be less than 255 characters';
1672
- return
1673
- end
1674
-
1675
- @header = string
1676
- @margin_header = margin
1677
- @header_encoding = encoding
1660
+ set_header_footer_common(:header, string, margin, encoding)
1678
1661
  end
1679
1662
 
1680
1663
  #
@@ -1684,13 +1667,17 @@ def set_header(string = '', margin = 0.50, encoding = 0)
1684
1667
  # there.
1685
1668
  #
1686
1669
  def set_footer(string = '', margin = 0.50, encoding = 0)
1670
+ set_header_footer_common(:footer, string, margin, encoding)
1671
+ end
1672
+
1673
+ def set_header_footer_common(type, string, margin, encoding)
1687
1674
  string = convert_to_ascii_if_ascii(string)
1688
1675
 
1689
1676
  limit = encoding != 0 ? 255 *2 : 255
1690
1677
 
1691
1678
  # Handle utf8 strings
1692
1679
  if string.encoding == Encoding::UTF_8
1693
- string = string.encode('UTF-16BE')
1680
+ string = utf8_to_16be(string)
1694
1681
  encoding = 1
1695
1682
  end
1696
1683
 
@@ -1699,10 +1686,17 @@ def set_footer(string = '', margin = 0.50, encoding = 0)
1699
1686
  return
1700
1687
  end
1701
1688
 
1702
- @footer = string
1703
- @margin_footer = margin
1704
- @footer_encoding = encoding
1689
+ if type == :header
1690
+ @header = string
1691
+ @margin_header = margin
1692
+ @header_encoding = encoding
1693
+ else
1694
+ @footer = string
1695
+ @margin_footer = margin
1696
+ @footer_encoding = encoding
1697
+ end
1705
1698
  end
1699
+ private :set_header_footer_common
1706
1700
 
1707
1701
  #
1708
1702
  # Set the rows to repeat at the top of each printed page.
@@ -1987,7 +1981,7 @@ def set_print_scale(scale = 100)
1987
1981
  # worksheet in line with an Excel internal limitation.
1988
1982
  #
1989
1983
  def set_h_pagebreaks(breaks)
1990
- @hbreaks += breaks.kind_of?(Array) ? breaks : [breaks]
1984
+ @hbreaks += breaks.respond_to?(:to_ary) ? breaks : [breaks]
1991
1985
  end
1992
1986
 
1993
1987
  #
@@ -2013,7 +2007,7 @@ def set_h_pagebreaks(breaks)
2013
2007
  # it will override all manual page breaks.
2014
2008
  #
2015
2009
  def set_v_pagebreaks(breaks)
2016
- @vbreaks += breaks.kind_of?(Array) ? breaks : [breaks]
2010
+ @vbreaks += breaks.respond_to?(:to_ary) ? breaks : [breaks]
2017
2011
  end
2018
2012
 
2019
2013
  ###############################################################################
@@ -2087,9 +2081,9 @@ def parse_filter_expression(expression, tokens) #:nodoc:
2087
2081
  end
2088
2082
  expression_1 = parse_filter_tokens(expression, tokens[0..2])
2089
2083
  expression_2 = parse_filter_tokens(expression, tokens[4..6])
2090
- return [expression_1, conditional, expression_2].flatten
2084
+ [expression_1, conditional, expression_2].flatten
2091
2085
  else
2092
- return parse_filter_tokens(expression, tokens)
2086
+ parse_filter_tokens(expression, tokens)
2093
2087
  end
2094
2088
  end
2095
2089
  # private :parse_filter_expression
@@ -2554,28 +2548,28 @@ def write(*args)
2554
2548
  end
2555
2549
 
2556
2550
  # Match an array ref.
2557
- if token.kind_of?(Array)
2558
- return write_row(*args)
2559
- elsif token.kind_of?(Numeric)
2560
- return write_number(*args)
2551
+ if token.respond_to?(:to_ary)
2552
+ write_row(*args)
2553
+ elsif token.respond_to?(:coerce) # Numeric
2554
+ write_number(*args)
2561
2555
  # Match http, https or ftp URL
2562
2556
  elsif token =~ %r|^[fh]tt?ps?://| and @writing_url == 0
2563
- return write_url(*args)
2557
+ write_url(*args)
2564
2558
  # Match mailto:
2565
2559
  elsif token =~ %r|^mailto:| and @writing_url == 0
2566
- return write_url(*args)
2560
+ write_url(*args)
2567
2561
  # Match internal or external sheet link
2568
2562
  elsif token =~ %r!^(?:in|ex)ternal:! and @writing_url == 0
2569
- return write_url(*args)
2563
+ write_url(*args)
2570
2564
  # Match formula
2571
2565
  elsif token =~ /^=/
2572
- return write_formula(*args)
2566
+ write_formula(*args)
2573
2567
  # Match blank
2574
2568
  elsif token == ''
2575
2569
  args.delete_at(2) # remove the empty string from the parameter list
2576
- return write_blank(*args)
2570
+ write_blank(*args)
2577
2571
  else
2578
- return write_string(*args)
2572
+ write_string(*args)
2579
2573
  end
2580
2574
  end
2581
2575
 
@@ -2632,7 +2626,6 @@ def write_number(*args)
2632
2626
  tmp[col] = header + data + xl_double
2633
2627
  @table[row] = tmp
2634
2628
  else
2635
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
2636
2629
  append(header, data, xl_double)
2637
2630
  end
2638
2631
 
@@ -2703,8 +2696,7 @@ def write_string(*args)
2703
2696
 
2704
2697
  # Handle utf8 strings
2705
2698
  if str.encoding == Encoding::UTF_8
2706
- str_utf16le = NKF.nkf('-w16L0 -m0 -W', str)
2707
- str_utf16le.force_encoding('UTF-16LE')
2699
+ str_utf16le = utf8_to_16le(str)
2708
2700
  return write_utf16le_string(row, col, str_utf16le, args[3])
2709
2701
  end
2710
2702
 
@@ -2732,17 +2724,26 @@ def write_string(*args)
2732
2724
  data = [row, col, xf, @sinfo[:str_table][str]].pack('vvvV')
2733
2725
 
2734
2726
  # Store the data or write immediately depending on the compatibility mode.
2727
+ store_with_compatibility(row, col, header + data)
2728
+
2729
+ str_error
2730
+ end
2731
+
2732
+ def store_with_compatibility(row, col, data)
2735
2733
  if @compatibility != 0
2736
- tmp = []
2737
- tmp[col] = header + data
2738
- @table[row] = tmp
2734
+ store_to_table(row, col, data)
2739
2735
  else
2740
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
2741
- append(header, data)
2736
+ append(data)
2742
2737
  end
2738
+ end
2739
+ private :store_with_compatibility
2743
2740
 
2744
- str_error
2741
+ def store_to_table(row, col, data)
2742
+ tmp = []
2743
+ tmp[col] = data
2744
+ @table[row] = tmp
2745
2745
  end
2746
+ private :store_to_table
2746
2747
 
2747
2748
  #
2748
2749
  # :call-seq:
@@ -2805,14 +2806,7 @@ def write_blank(*args)
2805
2806
  data = [row, col, xf].pack('vvv')
2806
2807
 
2807
2808
  # Store the data or write immediately depending on the compatibility mode.
2808
- if @compatibility != 0
2809
- tmp = []
2810
- tmp[col] = header + data
2811
- @table[row] = tmp
2812
- else
2813
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
2814
- append(header, data)
2815
- end
2809
+ store_with_compatibility(row, col, header + data)
2816
2810
 
2817
2811
  0
2818
2812
  end
@@ -3103,29 +3097,12 @@ def write_formula(*args)
3103
3097
 
3104
3098
  return -1 if args.size < 3 # Check the number of args
3105
3099
 
3106
- record = 0x0006 # Record identifier
3107
- # length # Bytes to follow
3108
-
3109
3100
  row = args[0] # Zero indexed row
3110
3101
  col = args[1] # Zero indexed column
3111
3102
  formula = args[2].dup # The formula text string
3112
3103
  value = args[4] # The formula text string
3113
3104
 
3114
-
3115
3105
  xf = xf_record_index(row, col, args[3]) # The cell format
3116
- chn = 0x0000 # Must be zero
3117
- is_string = 0 # Formula evaluates to str
3118
- # num # Current value of formula
3119
- # grbi # Option flags
3120
-
3121
- # Excel normally stores the last calculated value of the formula in num.
3122
- # Clearly we are not in a position to calculate this "a priori". Instead
3123
- # we set num to zero and set the option flags in grbit to ensure
3124
- # automatic calculation of the formula when the file is opened.
3125
- # As a workaround for some non-Excel apps we also allow the user to
3126
- # specify the result of the formula.
3127
- #
3128
- num, grbit, is_string = encode_formula_result(value)
3129
3106
 
3130
3107
  # Check that row and col are valid and store max and min values
3131
3108
  return -2 if check_dimensions(row, col) != 0
@@ -3138,33 +3115,7 @@ def write_formula(*args)
3138
3115
  # because ruby doesn't have Perl's "wantarray"
3139
3116
  formula = @parser.parse_formula(formula, true)
3140
3117
 
3141
- # if ($@) {
3142
- # $@ =~ s/\n$// # Strip the \n used in the Formula.pm die()
3143
- # croak $@ # Re-raise the error
3144
- # }
3145
-
3146
- formlen = formula.bytesize # Length of the binary string
3147
- length = 0x16 + formlen # Length of the record data
3148
-
3149
- header = [record, length].pack("vv")
3150
- data = [row, col, xf].pack("vvv") +
3151
- num +
3152
- [grbit, chn, formlen].pack('vVv')
3153
-
3154
- # The STRING record if the formula evaluates to a string.
3155
- string = ''
3156
- string = get_formula_string(value) if is_string != 0
3157
-
3158
- # Store the data or write immediately depending on the compatibility mode.
3159
- if @compatibility != 0
3160
- tmp = []
3161
- tmp[col] = header + data + formula + string
3162
- @table[row] = tmp
3163
- else
3164
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
3165
- append(header, data, formula, string)
3166
- end
3167
-
3118
+ store_formula_common(row, col, xf, value, formula)
3168
3119
  0
3169
3120
  end
3170
3121
 
@@ -3250,7 +3201,7 @@ def write_row(*args)
3250
3201
  end
3251
3202
 
3252
3203
  # Catch non array refs passed by user.
3253
- unless args[2].kind_of?(Array)
3204
+ unless args[2].respond_to?(:to_ary)
3254
3205
  raise "Not an array ref in call to write_row() #{$!}";
3255
3206
  end
3256
3207
 
@@ -3259,7 +3210,7 @@ def write_row(*args)
3259
3210
  unless tokens.nil?
3260
3211
  tokens.each do |token|
3261
3212
  # Check for nested arrays
3262
- if token.kind_of?(Array)
3213
+ if token.respond_to?(:to_ary)
3263
3214
  ret = write_col(row, col, token, options)
3264
3215
  else
3265
3216
  ret = write(row, col, token, options)
@@ -3354,7 +3305,7 @@ def write_col(*args)
3354
3305
  end
3355
3306
 
3356
3307
  # Catch non array refs passed by user.
3357
- unless args[2].kind_of?(Array)
3308
+ unless args[2].respond_to?(:to_ary)
3358
3309
  raise "Not an array ref in call to write_row()";
3359
3310
  end
3360
3311
 
@@ -3702,14 +3653,14 @@ def image_mso_size=(val) # :nodoc:
3702
3653
  # Note: this is a function, not a method.
3703
3654
  #
3704
3655
  def xf_record_index(row, col, xf=nil) #:nodoc:
3705
- if xf.kind_of?(Format)
3706
- return xf.xf_index
3656
+ if xf.respond_to?(:xf_index)
3657
+ xf.xf_index
3707
3658
  elsif @row_formats.has_key?(row)
3708
- return @row_formats[row].xf_index
3659
+ @row_formats[row].xf_index
3709
3660
  elsif @col_formats.has_key?(col)
3710
- return @col_formats[col].xf_index
3661
+ @col_formats[col].xf_index
3711
3662
  else
3712
- return 0x0F
3663
+ 0x0F
3713
3664
  end
3714
3665
  end
3715
3666
  private :xf_record_index
@@ -3730,7 +3681,7 @@ def xf_record_index(row, col, xf=nil) #:nodoc:
3730
3681
  # Ex: ("A4", "Hello") is converted to (3, 0, "Hello").
3731
3682
  #
3732
3683
  def substitute_cellref(cell, *args) #:nodoc:
3733
- return [*args] if cell.kind_of?(Numeric)
3684
+ return [*args] if cell.respond_to?(:coerce) # Numeric
3734
3685
 
3735
3686
  cell.upcase!
3736
3687
 
@@ -3912,7 +3863,7 @@ def get_formula_string(string) #:nodoc:
3912
3863
 
3913
3864
  # Handle utf8 strings.
3914
3865
  if string.encoding == Encoding::UTF_8
3915
- string = string.encode('UTF-16BE')
3866
+ string = utf8_to_16be(string)
3916
3867
  encoding = 1
3917
3868
  end
3918
3869
 
@@ -4113,9 +4064,6 @@ def repeat_formula(*args) #:nodoc:
4113
4064
 
4114
4065
  return -1 if (args.size < 2) # Check the number of args
4115
4066
 
4116
- record = 0x0006 # Record identifier
4117
- # length # Bytes to follow
4118
-
4119
4067
  row = args.shift # Zero indexed row
4120
4068
  col = args.shift # Zero indexed column
4121
4069
  formula_ref = args.shift # Array ref with formula tokens
@@ -4126,7 +4074,7 @@ def repeat_formula(*args) #:nodoc:
4126
4074
  raise "Odd number of elements in pattern/replacement list" if pairs.size % 2 != 0
4127
4075
 
4128
4076
  # Check that formula is an array ref
4129
- raise "Not a valid formula" unless formula_ref.kind_of?(Array)
4077
+ raise "Not a valid formula" unless formula_ref.respond_to?(:to_ary)
4130
4078
 
4131
4079
  tokens = formula_ref.join("\t").split("\t")
4132
4080
 
@@ -4158,11 +4106,15 @@ def repeat_formula(*args) #:nodoc:
4158
4106
  raise "Unrecognised token in formula" unless formula
4159
4107
 
4160
4108
  xf = xf_record_index(row, col, format) # The cell format
4161
- chn = 0x0000 # Must be zero
4162
- is_string = 0 # Formula evaluates to str
4163
- # num # Current value of formula
4164
- # grbit # Option flags
4165
4109
 
4110
+ # Check that row and col are valid and store max and min values
4111
+ return -2 if check_dimensions(row, col) != 0
4112
+
4113
+ store_formula_common(row, col, xf, value, formula)
4114
+ 0
4115
+ end
4116
+
4117
+ def store_formula_common(row, col, xf, value, formula)
4166
4118
  # Excel normally stores the last calculated value of the formula in $num.
4167
4119
  # Clearly we are not in a position to calculate this "a priori". Instead
4168
4120
  # we set $num to zero and set the option flags in $grbit to ensure
@@ -4170,14 +4122,16 @@ def repeat_formula(*args) #:nodoc:
4170
4122
  # As a workaround for some non-Excel apps we also allow the user to
4171
4123
  # specify the result of the formula.
4172
4124
  #
4125
+ # is_string # Formula evaluates to str
4126
+ # num # Current value of formula
4127
+ # grbit # Option flags
4173
4128
  num, grbit, is_string = encode_formula_result(value)
4174
4129
 
4175
- # Check that row and col are valid and store max and min values
4176
- return -2 if check_dimensions(row, col) != 0
4177
-
4130
+ record = 0x0006 # Record identifier
4131
+ chn = 0x0000 # Must be zero
4178
4132
 
4179
4133
  formlen = formula.bytesize # Length of the binary string
4180
- length = 0x16 + formlen # Length of the record data
4134
+ length = 0x16 + formlen # Length of the record data
4181
4135
 
4182
4136
  header = [record, length].pack("vv")
4183
4137
  data = [row, col, xf].pack("vvv") +
@@ -4188,19 +4142,10 @@ def repeat_formula(*args) #:nodoc:
4188
4142
  string = ''
4189
4143
  string = get_formula_string(value) if is_string != 0
4190
4144
 
4191
-
4192
4145
  # Store the data or write immediately depending on the compatibility mode.
4193
- if @compatibility != 0
4194
- tmp = []
4195
- tmp[col] = header + data + formula + string
4196
- @table[row] = tmp
4197
- else
4198
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
4199
- append(header, data, formula, string)
4200
- end
4201
-
4202
- 0
4146
+ store_with_compatibility(row, col, header + data + formula + string)
4203
4147
  end
4148
+ private :store_formula_common
4204
4149
 
4205
4150
  #
4206
4151
  # :call-seq:
@@ -4345,7 +4290,7 @@ def write_url_range(*args)
4345
4290
  # in order to protect the callers args. We don't use "local @_" in case of
4346
4291
  # perl50005 threads.
4347
4292
  #
4348
- args[5], args[6] = [ args[6], args[5] ] if args[5].kind_of?(Format)
4293
+ args[5], args[6] = [ args[6], args[5] ] if args[5].respond_to?(:xf_index)
4349
4294
 
4350
4295
  url = args[4]
4351
4296
 
@@ -4420,7 +4365,6 @@ def write_url_web(row1, col1, row2, col2, url, str = nil, format = nil) #:
4420
4365
  data = [row1, row2, col1, col2].pack("vvvv")
4421
4366
 
4422
4367
  # Write the packed data
4423
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
4424
4368
  append( header, data,unknown1,options,unknown2,url_len,url)
4425
4369
 
4426
4370
  error
@@ -4491,7 +4435,6 @@ def write_url_internal(row1, col1, row2, col2, url, str = nil, format = nil)
4491
4435
  data = [row1, row2, col1, col2].pack("vvvv")
4492
4436
 
4493
4437
  # Write the packed data
4494
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
4495
4438
  append( header, data, unknown1, options, url_len, url)
4496
4439
 
4497
4440
  error
@@ -4542,21 +4485,7 @@ def write_url_external(row1, col1, row2, col2, url, str = nil, format = nil)
4542
4485
  absolute = 0x00
4543
4486
  absolute = 0x02 if url =~ /^[A-Za-z]:/
4544
4487
 
4545
- # Determine if the link contains a sheet reference and change some of the
4546
- # parameters accordingly.
4547
- # Split the dir name and sheet name (if it exists)
4548
- #
4549
- dir_long , sheet = url.split(/\#/)
4550
- link_type = 0x01 | absolute
4551
-
4552
- unless sheet.nil?
4553
- link_type |= 0x08
4554
- sheet_len = [sheet.bytesize + 0x01].pack("V")
4555
- sheet = sheet.split('').join("\0") + "\0\0\0"
4556
- else
4557
- sheet_len = ''
4558
- sheet = ''
4559
- end
4488
+ dir_long, link_type, sheet_len, sheet = analyze_link(url, absolute)
4560
4489
 
4561
4490
  # Pack the link type
4562
4491
  link_type = link_type.pack("V")
@@ -4606,7 +4535,6 @@ def write_url_external(row1, col1, row2, col2, url, str = nil, format = nil)
4606
4535
  header = [record, length].pack("vv")
4607
4536
 
4608
4537
  # Write the packed data
4609
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
4610
4538
  append(header, data)
4611
4539
 
4612
4540
  error
@@ -4640,26 +4568,11 @@ def write_url_external_net(row1, col1, row2, col2, url, str, format) #:nod
4640
4568
  @writing_url = 0
4641
4569
  return error if error == -2
4642
4570
 
4643
- # Determine if the link contains a sheet reference and change some of the
4644
- # parameters accordingly.
4645
- # Split the dir name and sheet name (if it exists)
4646
- #
4647
- dir_long , sheet = url.split(/\#/)
4648
- link_type = 0x0103 # Always absolute
4649
-
4650
- unless sheet.nil?
4651
- link_type |= 0x08
4652
- sheet_len = [sheet.bytesize + 0x01].pack("V")
4653
- sheet = sheet.split('').join("\0") + "\0\0\0"
4654
- else
4655
- sheet_len = ''
4656
- sheet = ''
4657
- end
4571
+ dir_long, link_type, sheet_len, sheet = analyze_link(url)
4658
4572
 
4659
4573
  # Pack the link type
4660
4574
  link_type = [link_type].pack("V")
4661
4575
 
4662
-
4663
4576
  # Make the string null terminated
4664
4577
  dir_long += "\0"
4665
4578
 
@@ -4686,13 +4599,33 @@ def write_url_external_net(row1, col1, row2, col2, url, str, format) #:nod
4686
4599
  header = [record, length].pack("vv")
4687
4600
 
4688
4601
  # Write the packed data
4689
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
4690
4602
  append(header, data)
4691
4603
 
4692
4604
  error
4693
4605
  end
4694
4606
  private :write_url_external_net
4695
4607
 
4608
+ # Determine if the link contains a sheet reference and change some of the
4609
+ # parameters accordingly.
4610
+ # Split the dir name and sheet name (if it exists)
4611
+ #
4612
+ def analyze_link(url, absolute = nil)
4613
+ dir_long , sheet = url.split(/\#/)
4614
+ link_type = absolute ? (0x01 | absolute) : 0x0103
4615
+
4616
+ unless sheet.nil?
4617
+ link_type |= 0x08
4618
+ sheet_len = [sheet.bytesize + 0x01].pack("V")
4619
+ sheet = sheet.split('').join("\0") + "\0\0\0"
4620
+ else
4621
+ sheet_len = ''
4622
+ sheet = ''
4623
+ end
4624
+
4625
+ [dir_long, link_type, sheet_len, sheet]
4626
+ end
4627
+ private :analyze_link
4628
+
4696
4629
  #
4697
4630
  # :call-seq:
4698
4631
  # write_date_time(row, col , date_string[, format])
@@ -4913,7 +4846,6 @@ def write_row_default(row, colMic, colMac) #:nodoc:
4913
4846
  header = [record, length].pack("vv")
4914
4847
  data = [row, colMic, colMac, miyRw, irwMac, reserved, grbit, ixfe].pack("vvvvvvvv")
4915
4848
 
4916
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
4917
4849
  append(header, data)
4918
4850
  end
4919
4851
  private :write_row_default
@@ -4993,7 +4925,6 @@ def store_dimensions #:nodoc:
4993
4925
  fields = [row_min, row_max, col_min, col_max, reserved]
4994
4926
  data = fields.pack("VVvvv")
4995
4927
 
4996
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
4997
4928
  prepend(header, data)
4998
4929
  end
4999
4930
  # private :store_dimensions
@@ -5048,7 +4979,6 @@ def store_window2 #:nodoc:
5048
4979
  header = [record, length].pack("vv")
5049
4980
  data =[grbit, rwTop, colLeft, rgbHdr, wScaleSLV, wScaleNormal, reserved].pack("vvvVvvV")
5050
4981
 
5051
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
5052
4982
  append(header, data)
5053
4983
  end
5054
4984
  private :store_window2
@@ -5062,7 +4992,6 @@ def store_window2 #:nodoc:
5062
4992
  def store_page_view #:nodoc:
5063
4993
  return if @page_view == 0
5064
4994
  data = ['C8081100C808000000000040000000000900000000'].pack("H*")
5065
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
5066
4995
  append(data)
5067
4996
  end
5068
4997
  private :store_page_view
@@ -5088,7 +5017,6 @@ def store_tab_color #:nodoc:
5088
5017
  data = [record, zero, zero, zero, zero,
5089
5018
  zero, unknown, zero, color, zero].pack("vvvvvvvvvv")
5090
5019
 
5091
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
5092
5020
  append(header, data)
5093
5021
  end
5094
5022
  private :store_tab_color
@@ -5109,7 +5037,6 @@ def store_defrow #:nodoc:
5109
5037
  header = [record, length].pack("vv")
5110
5038
  data = [grbit, height].pack("vv")
5111
5039
 
5112
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5113
5040
  prepend(header, data)
5114
5041
  end
5115
5042
  private :store_defrow
@@ -5129,7 +5056,6 @@ def store_defcol #:nodoc:
5129
5056
  header = [record, length].pack("vv")
5130
5057
  data = [colwidth].pack("v")
5131
5058
 
5132
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5133
5059
  prepend(header, data)
5134
5060
  end
5135
5061
  private :store_defcol
@@ -5170,7 +5096,7 @@ def store_colinfo(firstcol=0, lastcol=0, width=8.43, format=nil, hidden=0, level
5170
5096
  reserved = 0x00 # Reserved
5171
5097
 
5172
5098
  # Check for a format object
5173
- if !format.nil? && format.kind_of?(Format)
5099
+ if !format.nil? && format.respond_to?(:xf_index)
5174
5100
  ixfe = format.xf_index
5175
5101
  else
5176
5102
  ixfe = 0x0F
@@ -5190,7 +5116,6 @@ def store_colinfo(firstcol=0, lastcol=0, width=8.43, format=nil, hidden=0, level
5190
5116
  data = [firstcol, lastcol, coldx,
5191
5117
  ixfe, grbit, reserved].pack("vvvvvC")
5192
5118
 
5193
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5194
5119
  prepend(header, data)
5195
5120
  end
5196
5121
  # private :store_colinfo
@@ -5211,7 +5136,6 @@ def store_filtermode #:nodoc:
5211
5136
 
5212
5137
  header = [record, length].pack('vv')
5213
5138
 
5214
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5215
5139
  prepend(header)
5216
5140
  end
5217
5141
  # private :store_filtermode
@@ -5233,7 +5157,6 @@ def store_autofilterinfo #:nodoc:
5233
5157
  header = [record, length].pack('vv')
5234
5158
  data = [num_filters].pack('v')
5235
5159
 
5236
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5237
5160
  prepend(header, data)
5238
5161
  end
5239
5162
  private :store_autofilterinfo
@@ -5276,7 +5199,6 @@ def store_selection(first_row=0, first_col=0, last_row = nil, last_col =nil) #
5276
5199
  data = [pnn, rwAct, colAct, irefAct, cref,
5277
5200
  rwFirst, rwLast, colFirst, colLast].pack('CvvvvvvCC')
5278
5201
 
5279
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
5280
5202
  append(header, data)
5281
5203
  end
5282
5204
  # private :store_selection
@@ -5303,7 +5225,6 @@ def store_externcount(count) #:nodoc:
5303
5225
  header = [record, length].pack('vv')
5304
5226
  data = [cxals].pack('v')
5305
5227
 
5306
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5307
5228
  prepend(header, data)
5308
5229
  end
5309
5230
  private :store_externcount
@@ -5342,7 +5263,6 @@ def store_externsheet(sheetname) #:nodoc:
5342
5263
  header = [record, length].pack('vv')
5343
5264
  data = [cch, rgch].pack('CC')
5344
5265
 
5345
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5346
5266
  prepend(header, data, sheetname)
5347
5267
  end
5348
5268
  private :store_externsheet
@@ -5402,7 +5322,6 @@ def store_panes(y=0, x=0, rwtop=nil, colleft=nil, no_split=nil, pnnAct=nil) #
5402
5322
  header = [record, length].pack('vv')
5403
5323
  data = [x, y, rwtop, colleft, pnnAct].pack('vvvvv')
5404
5324
 
5405
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
5406
5325
  append(header, data)
5407
5326
  end
5408
5327
  private :store_panes
@@ -5463,7 +5382,6 @@ def store_setup #:nodoc:
5463
5382
  data2 = numHdr + numFtr
5464
5383
  data3 = [iCopies].pack('v')
5465
5384
 
5466
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5467
5385
  prepend(header, data1, data2, data3)
5468
5386
 
5469
5387
  end
@@ -5476,27 +5394,7 @@ def store_setup #:nodoc:
5476
5394
  # Store the header caption BIFF record.
5477
5395
  #
5478
5396
  def store_header #:nodoc:
5479
- record = 0x0014 # Record identifier
5480
- # length # Bytes to follow
5481
-
5482
- str = @header # header string
5483
- cch = str.bytesize # Length of header string
5484
- encoding = @header_encoding # Character encoding
5485
-
5486
-
5487
- # Character length is num of chars not num of bytes
5488
- cch /= 2 if encoding != 0
5489
-
5490
- # Change the UTF-16 name from BE to LE
5491
- str = str.unpack('v*').pack('n*') if encoding != 0
5492
-
5493
- length = 3 + str.bytesize
5494
-
5495
- header = [record, length].pack('vv')
5496
- data = [cch, encoding].pack('vC')
5497
-
5498
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5499
- prepend(header, data, str)
5397
+ store_header_footer_common(:header)
5500
5398
  end
5501
5399
  private :store_header
5502
5400
 
@@ -5507,13 +5405,24 @@ def store_header #:nodoc:
5507
5405
  # Store the footer caption BIFF record.
5508
5406
  #
5509
5407
  def store_footer #:nodoc:
5510
- record = 0x0015 # Record identifier
5511
- # length; # Bytes to follow
5512
-
5513
- str = @footer # footer string
5514
- cch = str.bytesize # Length of ooter string
5515
- encoding = @footer_encoding # Character encoding
5408
+ store_header_footer_common(:footer)
5409
+ end
5410
+ private :store_footer
5516
5411
 
5412
+ #
5413
+ # type : :header / :footer
5414
+ #
5415
+ def store_header_footer_common(type)
5416
+ if type == :header
5417
+ record = 0x0014
5418
+ str = @header
5419
+ encoding = @header_encoding
5420
+ else
5421
+ record = 0x0015
5422
+ str = @footer
5423
+ encoding = @footer_encoding
5424
+ end
5425
+ cch = str.bytesize # Length of header/footer string
5517
5426
 
5518
5427
  # Character length is num of chars not num of bytes
5519
5428
  cch /= 2 if encoding != 0
@@ -5524,12 +5433,11 @@ def store_footer #:nodoc:
5524
5433
  length = 3 + str.bytesize
5525
5434
 
5526
5435
  header = [record, length].pack('vv')
5527
- data = [cch, encoding].pack('vC')
5436
+ data = [cch, encoding].pack('vC')
5528
5437
 
5529
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5530
5438
  prepend(header, data, str)
5531
5439
  end
5532
- private :store_footer
5440
+ private :store_header_footer_common
5533
5441
 
5534
5442
  ###############################################################################
5535
5443
  #
@@ -5538,16 +5446,7 @@ def store_footer #:nodoc:
5538
5446
  # Store the horizontal centering HCENTER BIFF record.
5539
5447
  #
5540
5448
  def store_hcenter #:nodoc:
5541
- record = 0x0083 # Record identifier
5542
- length = 0x0002 # Bytes to follow
5543
-
5544
- fHCenter = @hcenter # Horizontal centering
5545
-
5546
- header = [record, length].pack('vv')
5547
- data = [fHCenter].pack('v')
5548
-
5549
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5550
- prepend(header, data)
5449
+ store_biff_common(:hcenter)
5551
5450
  end
5552
5451
  private :store_hcenter
5553
5452
 
@@ -5558,16 +5457,7 @@ def store_hcenter #:nodoc:
5558
5457
  # Store the vertical centering VCENTER BIFF record.
5559
5458
  #
5560
5459
  def store_vcenter #:nodoc:
5561
- record = 0x0084 # Record identifier
5562
- length = 0x0002 # Bytes to follow
5563
-
5564
- mfVCenter = @vcenter # Horizontal centering
5565
-
5566
- header = [record, length].pack('vv')
5567
- data = [mfVCenter].pack('v')
5568
-
5569
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5570
- prepend(header, data)
5460
+ store_biff_common(:vcenter)
5571
5461
  end
5572
5462
  private :store_vcenter
5573
5463
 
@@ -5578,18 +5468,7 @@ def store_vcenter #:nodoc:
5578
5468
  # Store the LEFTMARGIN BIFF record.
5579
5469
  #
5580
5470
  def store_margin_left #:nodoc:
5581
- record = 0x0026 # Record identifier
5582
- length = 0x0008 # Bytes to follow
5583
-
5584
- margin = @margin_left # Margin in inches
5585
-
5586
- header = [record, length].pack('vv')
5587
- data = [margin].pack('d')
5588
-
5589
- data = data.reverse if @byte_order != 0 && @byte_order != ''
5590
-
5591
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5592
- prepend(header, data)
5471
+ store_margin_common(0x0026, 0x0008, @margin_left)
5593
5472
  end
5594
5473
  private :store_margin_left
5595
5474
 
@@ -5600,18 +5479,7 @@ def store_margin_left #:nodoc:
5600
5479
  # Store the RIGHTMARGIN BIFF record.
5601
5480
  #
5602
5481
  def store_margin_right #:nodoc:
5603
- record = 0x0027 # Record identifier
5604
- length = 0x0008 # Bytes to follow
5605
-
5606
- margin = @margin_right # Margin in inches
5607
-
5608
- header = [record, length].pack('vv')
5609
- data = [margin].pack('d')
5610
-
5611
- data = data.reverse if @byte_order != 0 && @byte_order != ''
5612
-
5613
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5614
- prepend(header, data)
5482
+ store_margin_common(0x0027, 0x0008, @margin_right)
5615
5483
  end
5616
5484
  private :store_margin_right
5617
5485
 
@@ -5622,18 +5490,7 @@ def store_margin_right #:nodoc:
5622
5490
  # Store the TOPMARGIN BIFF record.
5623
5491
  #
5624
5492
  def store_margin_top #:nodoc:
5625
- record = 0x0028 # Record identifier
5626
- length = 0x0008 # Bytes to follow
5627
-
5628
- margin = @margin_top # Margin in inches
5629
-
5630
- header = [record, length].pack('vv')
5631
- data = [margin].pack('d')
5632
-
5633
- data = data.reverse if @byte_order != 0 && @byte_order != ''
5634
-
5635
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5636
- prepend(header, data)
5493
+ store_margin_common(0x0028, 0x0008, @margin_top)
5637
5494
  end
5638
5495
  private :store_margin_top
5639
5496
 
@@ -5644,20 +5501,24 @@ def store_margin_top #:nodoc:
5644
5501
  # Store the BOTTOMMARGIN BIFF record.
5645
5502
  #
5646
5503
  def store_margin_bottom #:nodoc:
5647
- record = 0x0029 # Record identifier
5648
- length = 0x0008 # Bytes to follow
5649
-
5650
- margin = @margin_bottom # Margin in inches
5504
+ store_margin_common(0x0029, 0x0008, @margin_bottom)
5505
+ end
5506
+ private :store_margin_bottom
5651
5507
 
5508
+ #
5509
+ # record : Record identifier
5510
+ # length : bytes to follow
5511
+ # margin : Margin in inches
5512
+ #
5513
+ def store_margin_common(record, length, margin)
5652
5514
  header = [record, length].pack('vv')
5653
5515
  data = [margin].pack('d')
5654
5516
 
5655
5517
  data = data.reverse if @byte_order != 0 && @byte_order != ''
5656
5518
 
5657
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5658
5519
  prepend(header, data)
5659
5520
  end
5660
- private :store_margin_bottom
5521
+ private :store_margin_common
5661
5522
 
5662
5523
  ###############################################################################
5663
5524
  #
@@ -5691,7 +5552,6 @@ def merge_cells(*args) #:nodoc:
5691
5552
  header = [record, length].pack("vv")
5692
5553
  data = [cref, rwFirst, rwLast, colFirst, colLast].pack("vvvvv")
5693
5554
 
5694
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
5695
5555
  append(header, data)
5696
5556
  end
5697
5557
 
@@ -5702,16 +5562,7 @@ def merge_cells(*args) #:nodoc:
5702
5562
  # Write the PRINTHEADERS BIFF record.
5703
5563
  #
5704
5564
  def store_print_headers #:nodoc:
5705
- record = 0x002a # Record identifier
5706
- length = 0x0002 # Bytes to follow
5707
-
5708
- fPrintRwCol = @print_headers # Boolean flag
5709
-
5710
- header = [record, length].pack("vv")
5711
- data = [fPrintRwCol].pack("v")
5712
-
5713
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5714
- prepend(header, data)
5565
+ store_biff_common(:print_headers)
5715
5566
  end
5716
5567
  private :store_print_headers
5717
5568
 
@@ -5723,18 +5574,33 @@ def store_print_headers #:nodoc:
5723
5574
  # GRIDSET record.
5724
5575
  #
5725
5576
  def store_print_gridlines #:nodoc:
5726
- record = 0x002b # Record identifier
5727
- length = 0x0002 # Bytes to follow
5577
+ store_biff_common(:print_gridlines)
5578
+ end
5579
+ private :store_print_gridlines
5728
5580
 
5729
- fPrintGrid = @print_gridlines # Boolean flag
5581
+ def store_biff_common(type)
5582
+ case type
5583
+ when :hcenter
5584
+ record = 0x0083
5585
+ flag = @hcenter
5586
+ when :vcenter
5587
+ record = 0x0084
5588
+ flag = @vcenter
5589
+ when :print_headers
5590
+ record = 0x002a
5591
+ flag = @print_headers
5592
+ when :print_gridlines
5593
+ record = 0x002b
5594
+ flag = @print_gridlines
5595
+ end
5596
+ length = 0x0002
5730
5597
 
5731
5598
  header = [record, length].pack("vv")
5732
- data = [fPrintGrid].pack("v")
5599
+ data = [flag].pack("v")
5733
5600
 
5734
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5735
5601
  prepend(header, data)
5736
5602
  end
5737
- private :store_print_gridlines
5603
+ private :store_biff_common
5738
5604
 
5739
5605
  ###############################################################################
5740
5606
  #
@@ -5752,7 +5618,6 @@ def store_gridset #:nodoc:
5752
5618
  header = [record, length].pack("vv")
5753
5619
  data = [fGridSet].pack("v")
5754
5620
 
5755
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5756
5621
  prepend(header, data)
5757
5622
  end
5758
5623
  private :store_gridset
@@ -5798,7 +5663,6 @@ def store_guts #:nodoc:
5798
5663
  header = [record, length].pack("vv")
5799
5664
  data = [dxRwGut, dxColGut, row_level, col_level].pack("vvvv")
5800
5665
 
5801
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5802
5666
  prepend(header, data)
5803
5667
  end
5804
5668
  private :store_guts
@@ -5827,7 +5691,6 @@ def store_wsbool #:nodoc:
5827
5691
  header = [record, length].pack("vv")
5828
5692
  data = [grbit].pack('v')
5829
5693
 
5830
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5831
5694
  prepend(header, data)
5832
5695
  end
5833
5696
  private :store_wsbool
@@ -5839,26 +5702,7 @@ def store_wsbool #:nodoc:
5839
5702
  # Write the HORIZONTALPAGEBREAKS BIFF record.
5840
5703
  #
5841
5704
  def store_hbreak #:nodoc:
5842
- # Return if the user hasn't specified pagebreaks
5843
- return if @hbreaks.size == 0
5844
-
5845
- # Sort and filter array of page breaks
5846
- breaks = sort_pagebreaks(@hbreaks)
5847
-
5848
- record = 0x001b # Record identifier
5849
- cbrk = breaks.size # Number of page breaks
5850
- length = 2 + 6 * cbrk # Bytes to follow
5851
-
5852
- header = [record, length].pack("vv")
5853
- data = [cbrk].pack("v")
5854
-
5855
- # Append each page break
5856
- breaks.each do |brk|
5857
- data += [brk, 0x0000, 0x00ff].pack("vvv")
5858
- end
5859
-
5860
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5861
- prepend(header, data)
5705
+ store_breaks_common(@hbreaks)
5862
5706
  end
5863
5707
  private :store_hbreak
5864
5708
 
@@ -5869,28 +5713,28 @@ def store_hbreak #:nodoc:
5869
5713
  # Write the VERTICALPAGEBREAKS BIFF record.
5870
5714
  #
5871
5715
  def store_vbreak #:nodoc:
5872
- # Return if the user hasn't specified pagebreaks
5873
- return if @vbreaks.size == 0
5716
+ store_breaks_common(@vbreaks)
5717
+ end
5718
+ private :store_vbreak
5874
5719
 
5875
- # Sort and filter array of page breaks
5876
- breaks = sort_pagebreaks(@vbreaks)
5720
+ def store_breaks_common(breaks)
5721
+ unless breaks.empty?
5722
+ record = breaks == @vbreaks ? 0x001a : 0x001b # Record identifier
5723
+ cbrk = breaks.size # Number of page breaks
5724
+ length = 2 + 6 * cbrk # Bytes to follow
5877
5725
 
5878
- record = 0x001a # Record identifier
5879
- cbrk = breaks.size # Number of page breaks
5880
- length = 2 + 6*cbrk # Bytes to follow
5726
+ header = [record, length].pack("vv")
5727
+ data = [cbrk].pack("v")
5881
5728
 
5882
- header = [record, length].pack("vv")
5883
- data = [cbrk].pack("v")
5729
+ # Append each sorted page break
5730
+ sort_pagebreaks(breaks).each do |brk|
5731
+ data += [brk, 0x0000, 0x00ff].pack("vvv")
5732
+ end
5884
5733
 
5885
- # Append each page break
5886
- breaks.each do |brk|
5887
- data += [brk, 0x0000, 0x00ff].pack("vvv")
5734
+ prepend(header, data)
5888
5735
  end
5889
-
5890
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5891
- prepend(header, data)
5892
5736
  end
5893
- private :store_vbreak
5737
+ private :store_breaks_common
5894
5738
 
5895
5739
  ###############################################################################
5896
5740
  #
@@ -5899,19 +5743,7 @@ def store_vbreak #:nodoc:
5899
5743
  # Set the Biff PROTECT record to indicate that the worksheet is protected.
5900
5744
  #
5901
5745
  def store_protect #:nodoc:
5902
- # Exit unless sheet protection has been specified
5903
- return if @protect == 0
5904
-
5905
- record = 0x0012 # Record identifier
5906
- length = 0x0002 # Bytes to follow
5907
-
5908
- fLock = @protect # Worksheet is protected
5909
-
5910
- header = [record, length].pack("vv")
5911
- data = [fLock].pack("v")
5912
-
5913
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5914
- prepend(header, data)
5746
+ store_protect_common
5915
5747
  end
5916
5748
  private :store_protect
5917
5749
 
@@ -5922,21 +5754,29 @@ def store_protect #:nodoc:
5922
5754
  # Set the Biff OBJPROTECT record to indicate that objects are protected.
5923
5755
  #
5924
5756
  def store_obj_protect #:nodoc:
5925
- # Exit unless sheet protection has been specified
5926
- return if @protect == 0
5757
+ store_protect_common(:obj)
5758
+ end
5759
+ private :store_obj_protect
5927
5760
 
5928
- record = 0x0063 # Record identifier
5929
- length = 0x0002 # Bytes to follow
5761
+ def store_protect_common(type = nil)
5762
+ if @protect != 0
5763
+ record = if type == :obj # Record identifier
5764
+ 0x0063 # store_obj_protect
5765
+ else
5766
+ 0x0012 # store_protect
5767
+ end
5768
+ length = 0x0002 # Bytes to follow
5930
5769
 
5931
- fLock = @protect # Worksheet is protected
5770
+ fLock = @protect # Worksheet is protected
5932
5771
 
5933
- header = [record, length].pack("vv")
5934
- data = [fLock].pack("v")
5772
+ header = [record, length].pack("vv")
5773
+ data = [fLock].pack("v")
5935
5774
 
5936
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5937
- prepend(header, data)
5775
+ prepend(header, data)
5776
+ end
5938
5777
  end
5939
- private :store_obj_protect
5778
+ private :store_protect_common
5779
+
5940
5780
 
5941
5781
  ###############################################################################
5942
5782
  #
@@ -5956,7 +5796,6 @@ def store_password #:nodoc:
5956
5796
  header = [record, length].pack("vv")
5957
5797
  data = [wPassword].pack("v")
5958
5798
 
5959
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
5960
5799
  prepend(header, data)
5961
5800
  end
5962
5801
  private :store_password
@@ -6024,7 +5863,6 @@ def store_table #:nodoc:
6024
5863
  # Rewrite the min and max cols for user defined row record.
6025
5864
  packed_row = @row_data[row]
6026
5865
  packed_row[6..9] = [col_min, col_max].pack('vv')
6027
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) packed_row\n" if defined?($debug)
6028
5866
  append(packed_row)
6029
5867
  else
6030
5868
  # Write a default Row record if there isn't a user defined ROW.
@@ -6048,7 +5886,6 @@ def store_table #:nodoc:
6048
5886
  if @table[rw]
6049
5887
  @table[rw].each do |clm|
6050
5888
  next unless clm
6051
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) cell_data\n" if defined?($debug)
6052
5889
  append(clm)
6053
5890
  length = clm.bytesize
6054
5891
  row_offset += length
@@ -6094,7 +5931,6 @@ def store_dbcell(row_offset, cell_offsets) #:nodoc:
6094
5931
  data += [co].pack('v')
6095
5932
  end
6096
5933
 
6097
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
6098
5934
  append(header, data)
6099
5935
  end
6100
5936
  private :store_dbcell
@@ -6125,7 +5961,6 @@ def store_index #:nodoc:
6125
5961
  data += [index + @offset + 20 + length + 4].pack('V')
6126
5962
  end
6127
5963
 
6128
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
6129
5964
  prepend(header, data)
6130
5965
  end
6131
5966
  private :store_index
@@ -6197,7 +6032,7 @@ def insert_chart(*args)
6197
6032
  scale_x = args[5] || 1
6198
6033
  scale_y = args[6] || 1
6199
6034
 
6200
- if chart.kind_of?(Chart)
6035
+ if chart.respond_to?(:embedded)
6201
6036
  print "Not a embedded style Chart object in insert_chart()" unless chart.embedded
6202
6037
  else
6203
6038
  # Assume an external bin filename.
@@ -6359,16 +6194,10 @@ def position_object(col_start, row_start, x1, y1, width, height) #:nodoc:
6359
6194
  # height; # Height of image frame
6360
6195
 
6361
6196
  # Adjust start column for offsets that are greater than the col width
6362
- while x1 >= size_col(col_start)
6363
- x1 -= size_col(col_start)
6364
- col_start += 1
6365
- end
6197
+ x1, col_start = adjust_col_position(x1, col_start)
6366
6198
 
6367
6199
  # Adjust start row for offsets that are greater than the row height
6368
- while y1 >= size_row(row_start)
6369
- y1 -= size_row(row_start)
6370
- row_start += 1
6371
- end
6200
+ y1, row_start = adjust_row_position(y1, row_start)
6372
6201
 
6373
6202
  # Initialise end cell to the same as the start cell
6374
6203
  col_end = col_start
@@ -6378,16 +6207,10 @@ def position_object(col_start, row_start, x1, y1, width, height) #:nodoc:
6378
6207
  height += y1
6379
6208
 
6380
6209
  # Subtract the underlying cell widths to find the end cell of the image
6381
- while width >= size_col(col_end)
6382
- width -= size_col(col_end)
6383
- col_end += 1
6384
- end
6210
+ width, col_end = adjust_col_position(width, col_end)
6385
6211
 
6386
6212
  # Subtract the underlying cell heights to find the end cell of the image
6387
- while height >= size_row(row_end)
6388
- height -= size_row(row_end)
6389
- row_end += 1
6390
- end
6213
+ height, row_end = adjust_row_position(height, row_end)
6391
6214
 
6392
6215
  # Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
6393
6216
  # with zero eight or width.
@@ -6417,6 +6240,24 @@ def position_object(col_start, row_start, x1, y1, width, height) #:nodoc:
6417
6240
  ]
6418
6241
  end
6419
6242
 
6243
+ def adjust_col_position(x, col)
6244
+ while x >= size_col(col)
6245
+ x -= size_col(col)
6246
+ col += 1
6247
+ end
6248
+ [x, col]
6249
+ end
6250
+ private :adjust_col_position
6251
+
6252
+ def adjust_row_position(y, row)
6253
+ while y >= size_row(row)
6254
+ y -= size_row(row)
6255
+ row += 1
6256
+ end
6257
+ [y, row]
6258
+ end
6259
+ private :adjust_row_position
6260
+
6420
6261
  ###############################################################################
6421
6262
  #
6422
6263
  # _size_col($col)
@@ -6432,12 +6273,12 @@ def size_col(col) #:nodoc:
6432
6273
 
6433
6274
  # The relationship is different for user units less than 1.
6434
6275
  if width < 1
6435
- return (width *12).to_i
6276
+ (width *12).to_i
6436
6277
  else
6437
- return (width *7 +5 ).to_i
6278
+ (width *7 +5 ).to_i
6438
6279
  end
6439
6280
  else
6440
- return 64
6281
+ 64
6441
6282
  end
6442
6283
  end
6443
6284
  private :size_col
@@ -6455,12 +6296,12 @@ def size_row(row) #:nodoc:
6455
6296
  # Look up the cell value to see if it has been changed
6456
6297
  unless @row_sizes[row].nil?
6457
6298
  if @row_sizes[row] == 0
6458
- return 0
6299
+ 0
6459
6300
  else
6460
- return (4/3.0 * @row_sizes[row]).to_i
6301
+ (4/3.0 * @row_sizes[row]).to_i
6461
6302
  end
6462
6303
  else
6463
- return 17
6304
+ 17
6464
6305
  end
6465
6306
  end
6466
6307
  private :size_row
@@ -6483,7 +6324,6 @@ def store_zoom #:nodoc:
6483
6324
  header = [record, header].pack("vv")
6484
6325
  data = [@zoom, 100].pack("vv")
6485
6326
 
6486
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
6487
6327
  append(header, data)
6488
6328
  end
6489
6329
  private :store_zoom
@@ -6551,14 +6391,7 @@ def write_utf16be_string(*args)
6551
6391
  data = [row, col, xf, @sinfo[:str_table][str]].pack("vvvV")
6552
6392
 
6553
6393
  # Store the data or write immediately depending on the compatibility mode.
6554
- if @compatibility != 0
6555
- tmp = []
6556
- tmp[col] = header + data
6557
- @table[row] = tmp
6558
- else
6559
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
6560
- append(header, data)
6561
- end
6394
+ store_with_compatibility(row, col, header + data)
6562
6395
 
6563
6396
  str_error
6564
6397
  end
@@ -6716,7 +6549,6 @@ def store_autofilter(index, operator_1, token_1, #:nodoc:
6716
6549
  length = data.bytesize
6717
6550
  header = [record, length].pack('vv')
6718
6551
 
6719
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
6720
6552
  prepend(header, data)
6721
6553
  end
6722
6554
  # private :store_autofilter
@@ -6750,7 +6582,7 @@ def pack_doper(operator, token) #:nodoc:
6750
6582
 
6751
6583
  # Handle utf8 strings
6752
6584
  if string.encoding == Encoding::UTF_8
6753
- string = string.encode('UTF-16BE')
6585
+ string = utf8_to_16be(string)
6754
6586
  encodign = 1
6755
6587
  end
6756
6588
 
@@ -6840,25 +6672,7 @@ def pack_number_doper(operator, number) #:nodoc:
6840
6672
  # Turn the HoH that stores the images into an array for easier handling.
6841
6673
  #
6842
6674
  def prepare_images #:nodoc:
6843
- count = 0
6844
- images = []
6845
-
6846
- # We sort the images by row and column but that isn't strictly required.
6847
- #
6848
- rows = @images.keys.sort
6849
-
6850
- rows.each do |row|
6851
- cols = @images[row].keys.sort
6852
- cols.each do |col|
6853
- images.push(@images[row][col])
6854
- count += 1
6855
- end
6856
- end
6857
-
6858
- @images = {}
6859
- @images_array = images
6860
-
6861
- count
6675
+ prepare_common(:images)
6862
6676
  end
6863
6677
  # private :prepare_images
6864
6678
 
@@ -6869,24 +6683,7 @@ def prepare_images #:nodoc:
6869
6683
  # Turn the HoH that stores the comments into an array for easier handling.
6870
6684
  #
6871
6685
  def prepare_comments #:nodoc:
6872
- count = 0
6873
- comments = []
6874
-
6875
- # We sort the comments by row and column but that isn't strictly required.
6876
- #
6877
- rows = @comments.keys.sort
6878
- rows.each do |row|
6879
- cols = @comments[row].keys.sort
6880
- cols.each do |col|
6881
- comments.push(@comments[row][col])
6882
- count += 1
6883
- end
6884
- end
6885
-
6886
- @comments = {}
6887
- @comments_array = comments
6888
-
6889
- count
6686
+ prepare_common(:comments)
6890
6687
  end
6891
6688
  # private :prepare_comments
6892
6689
 
@@ -6897,25 +6694,43 @@ def prepare_comments #:nodoc:
6897
6694
  # Turn the HoH that stores the charts into an array for easier handling.
6898
6695
  #
6899
6696
  def prepare_charts #:nodoc:
6900
- count = 0
6901
- charts = []
6697
+ prepare_common(:charts)
6698
+ end
6699
+ # private :prepare_charts
6700
+
6701
+ def prepare_common(param)
6702
+ hash = {
6703
+ :images => @images, :comments => @comments, :charts => @charts
6704
+ }[param]
6705
+
6706
+ count = 0
6707
+ obj = []
6902
6708
 
6903
6709
  # We sort the charts by row and column but that isn't strictly required.
6904
6710
  #
6905
- rows = @charts.keys.sort
6711
+ rows = hash.keys.sort
6906
6712
  rows.each do |row|
6907
- cols = @charts[row].keys.sort
6713
+ cols = hash[row].keys.sort
6908
6714
  cols.each do |col|
6909
- charts.push(@charts[row][col])
6715
+ obj.push(hash[row][col])
6910
6716
  count += 1
6911
6717
  end
6912
6718
  end
6913
6719
 
6914
- @charts = {}
6915
- @charts_array = charts
6720
+ case param
6721
+ when :images
6722
+ @images = {}
6723
+ @images_array = obj
6724
+ when :comments
6725
+ @comments = {}
6726
+ @comments_array = obj
6727
+ when :charts
6728
+ @charts = {}
6729
+ @charts_array = obj
6730
+ end
6916
6731
  count
6917
6732
  end
6918
- # private :prepare_charts
6733
+ private :prepare_common
6919
6734
 
6920
6735
  ###############################################################################
6921
6736
  #
@@ -6973,18 +6788,13 @@ def store_images #:nodoc:
6973
6788
  dg_length += 128 * num_comments
6974
6789
  spgr_length += 128 * num_comments
6975
6790
 
6976
- data = store_mso_dg_container(dg_length) +
6977
- store_mso_dg(*ids) +
6978
- store_mso_spgr_container(spgr_length) +
6979
- store_mso_sp_container(40) +
6980
- store_mso_spgr() +
6981
- store_mso_sp(0x0, spid, 0x0005)
6982
- spid = spid + 1
6983
- data = data +
6791
+ data = store_parent_mso_record(dg_length, ids, spgr_length, spid)
6792
+ spid += 1
6793
+ data +=
6984
6794
  store_mso_sp_container(76) +
6985
6795
  store_mso_sp(75, spid, 0x0A00)
6986
- spid = spid + 1
6987
- data = data +
6796
+ spid += 1
6797
+ data +=
6988
6798
  store_mso_opt_image(image_id) +
6989
6799
  store_mso_client_anchor(2, *vertices) +
6990
6800
  store_mso_client_data()
@@ -7000,7 +6810,6 @@ def store_images #:nodoc:
7000
6810
  end
7001
6811
  length = data.bytesize
7002
6812
  header = [record, length].pack("vv")
7003
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7004
6813
  append(header, data)
7005
6814
 
7006
6815
  store_obj_image(i+1)
@@ -7010,6 +6819,25 @@ def store_images #:nodoc:
7010
6819
  end
7011
6820
  private :store_images
7012
6821
 
6822
+ def store_parent_mso_record(dg_length, ids, spgr_length, spid)
6823
+ store_mso_dg_container(dg_length) +
6824
+ store_mso_dg(*ids) +
6825
+ store_mso_spgr_container(spgr_length) +
6826
+ store_mso_sp_container(40) +
6827
+ store_mso_spgr() +
6828
+ store_mso_sp(0x0, spid, 0x0005)
6829
+ end
6830
+ private :store_parent_mso_record
6831
+
6832
+ def store_child_mso_record(spid, *vertices)
6833
+ store_mso_sp_container(88) +
6834
+ store_mso_sp(201, spid, 0x0A00) +
6835
+ store_mso_opt_filter +
6836
+ store_mso_client_anchor(1, *vertices) +
6837
+ store_mso_client_data
6838
+ end
6839
+ private :store_child_mso_record
6840
+
7013
6841
  ###############################################################################
7014
6842
  #
7015
6843
  # _store_charts()
@@ -7046,8 +6874,8 @@ def store_charts #:nodoc:
7046
6874
  width = 526
7047
6875
  height = 319
7048
6876
 
7049
- width *= scale_x if scale_x.kind_of?(Numeric) && scale_x != 0
7050
- height *= scale_y if scale_y.kind_of?(Numeric) && scale_y != 0
6877
+ width *= scale_x if scale_x.respond_to?(:coerce) && scale_x != 0
6878
+ height *= scale_y if scale_y.respond_to?(:coerce) && scale_y != 0
7051
6879
 
7052
6880
  # Calculate the positions of chart object.
7053
6881
  vertices = position_object( col,
@@ -7070,38 +6898,25 @@ def store_charts #:nodoc:
7070
6898
  spgr_length += 128 *num_comments
7071
6899
 
7072
6900
 
7073
- data = store_mso_dg_container(dg_length) +
7074
- store_mso_dg(*ids) +
7075
- store_mso_spgr_container(spgr_length) +
7076
- store_mso_sp_container(40) +
7077
- store_mso_spgr() +
7078
- store_mso_sp(0x0, spid, 0x0005)
6901
+ data = store_parent_mso_record(dg_length, ids, spgr_length, spid)
7079
6902
  spid += 1
7080
- data += store_mso_sp_container(112) +
7081
- store_mso_sp(201, spid, 0x0A00)
6903
+ data += store_mso_sp_container_sp(spid)
7082
6904
  spid += 1
7083
- data += store_mso_opt_chart() +
7084
- store_mso_client_anchor(0, *vertices) +
7085
- store_mso_client_data()
6905
+ data += store_mso_opt_chart_client_anchor_client_data(*vertices)
7086
6906
  else
7087
6907
  # Write the child MSODRAWIING record.
7088
- data = store_mso_sp_container(112) +
7089
- store_mso_sp(201, spid, 0x0A00)
6908
+ data = store_mso_sp_container_sp(spid)
7090
6909
  spid += 1
7091
- data += store_mso_opt_chart() +
7092
- store_mso_client_anchor(0, *vertices) +
7093
- store_mso_client_data()
6910
+ data += store_mso_opt_chart_client_anchor_client_data(*vertices)
7094
6911
  end
7095
6912
  length = data.bytesize
7096
6913
  header = [record, length].pack("vv")
7097
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7098
6914
  append(header, data)
7099
6915
 
7100
- store_obj_chart(num_objects+i+1)
6916
+ store_obj_chart(num_objects + i + 1)
7101
6917
  store_chart_binary(chart)
7102
6918
  end
7103
6919
 
7104
-
7105
6920
  # Simulate the EXTERNSHEET link between the chart and data using a formula
7106
6921
  # such as '=Sheet1!A1'.
7107
6922
  # TODO. Won't work for external data refs. Also should use a more direct
@@ -7114,6 +6929,18 @@ def store_charts #:nodoc:
7114
6929
  end
7115
6930
  private :store_charts
7116
6931
 
6932
+ def store_mso_sp_container_sp(spid)
6933
+ store_mso_sp_container(112) + store_mso_sp(201, spid, 0x0A00)
6934
+ end
6935
+ private :store_mso_sp_container_sp
6936
+
6937
+ def store_mso_opt_chart_client_anchor_client_data(*vertices)
6938
+ store_mso_opt_chart +
6939
+ store_mso_client_anchor(0, *vertices) +
6940
+ store_mso_client_data
6941
+ end
6942
+ private :store_mso_opt_chart_client_anchor_client_data
6943
+
7117
6944
  ###############################################################################
7118
6945
  #
7119
6946
  # _store_chart_binary
@@ -7122,18 +6949,16 @@ def store_charts #:nodoc:
7122
6949
  # or from an external binary file (for backwards compatibility).
7123
6950
  #
7124
6951
  def store_chart_binary(chart) #:nodoc:
7125
- if chart.kind_of?(Chart)
7126
- chart.close
7127
- tmp = chart.get_data
7128
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7129
- append(tmp)
7130
- else
6952
+ if chart.respond_to?(:to_str)
7131
6953
  filehandle = File.open(chart, "rb")
7132
6954
  # die "Couldn't open $filename in add_chart_ext(): $!.\n";
7133
6955
  while tmp = filehandle.read(4096)
7134
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7135
6956
  append(tmp)
7136
6957
  end
6958
+ else
6959
+ chart.close
6960
+ tmp = chart.get_data
6961
+ append(tmp)
7137
6962
  end
7138
6963
  end
7139
6964
  private :store_chart_binary
@@ -7176,32 +7001,18 @@ def store_filters #:nodoc:
7176
7001
  dg_length += 128 * num_comments
7177
7002
  spgr_length += 128 * num_comments
7178
7003
 
7179
- data = store_mso_dg_container(dg_length) +
7180
- store_mso_dg(*ids) +
7181
- store_mso_spgr_container(spgr_length) +
7182
- store_mso_sp_container(40) +
7183
- store_mso_spgr() +
7184
- store_mso_sp(0x0, spid, 0x0005)
7004
+ data = store_parent_mso_record(dg_length, ids, spgr_length, spid)
7185
7005
  spid += 1
7186
- data += store_mso_sp_container(88) +
7187
- store_mso_sp(201, spid, 0x0A00) +
7188
- store_mso_opt_filter() +
7189
- store_mso_client_anchor(1, *vertices) +
7190
- store_mso_client_data()
7006
+ data += store_child_mso_record(spid, *vertices)
7191
7007
  spid += 1
7192
7008
 
7193
7009
  else
7194
7010
  # Write the child MSODRAWIING record.
7195
- data = store_mso_sp_container(88) +
7196
- store_mso_sp(201, spid, 0x0A00) +
7197
- store_mso_opt_filter() +
7198
- store_mso_client_anchor(1, *vertices) +
7199
- store_mso_client_data()
7011
+ data = store_child_mso_record(spid, *vertices)
7200
7012
  spid += 1
7201
7013
  end
7202
7014
  length = data.bytesize
7203
7015
  header = [record, length].pack("vv")
7204
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7205
7016
  append(header, data)
7206
7017
 
7207
7018
  store_obj_filter(num_objects+i+1, col1 +i)
@@ -7266,12 +7077,7 @@ def store_comments #:nodoc:
7266
7077
  dg_length = 200 + 128*(num_comments -1)
7267
7078
  spgr_length = 176 + 128*(num_comments -1)
7268
7079
 
7269
- data = store_mso_dg_container(dg_length) +
7270
- store_mso_dg(*ids) +
7271
- store_mso_spgr_container(spgr_length) +
7272
- store_mso_sp_container(40) +
7273
- store_mso_spgr() +
7274
- store_mso_sp(0x0, spid, 0x0005)
7080
+ data = store_parent_mso_record(dg_length, ids, spgr_length, spid)
7275
7081
  spid += 1
7276
7082
  else
7277
7083
  data = ''
@@ -7286,7 +7092,6 @@ def store_comments #:nodoc:
7286
7092
  store_mso_client_data
7287
7093
  length = data.bytesize
7288
7094
  header = [record, length].pack("vv")
7289
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7290
7095
  append(header, data)
7291
7096
 
7292
7097
  store_obj_comment(num_objects + i + 1)
@@ -7334,7 +7139,6 @@ def store_mso_dg_container(length) #:nodoc:
7334
7139
  def store_mso_dg(instance, num_shapes, max_spid) #:nodoc:
7335
7140
  type = 0xF008
7336
7141
  version = 0
7337
- data = ''
7338
7142
  length = 8
7339
7143
  data = [num_shapes, max_spid].pack("VV")
7340
7144
 
@@ -7478,22 +7282,19 @@ def store_mso_opt_chart #:nodoc:
7478
7282
  data = ''
7479
7283
  length = nil
7480
7284
 
7481
- data = [0x007F].pack('v') + # Protection -> fLockAgainstGrouping
7482
- [0x01040104].pack('V') +
7483
- [0x00BF].pack('v') + # Text -> fFitTextToShape
7484
- [0x00080008].pack('V') +
7485
- [0x0181].pack('v') + # Fill Style -> fillColor
7285
+ data = store_mso_protection_and_text
7286
+ data += [0x0181].pack('v') + # Fill Style -> fillColor
7486
7287
  [0x0800004E].pack('V') +
7487
7288
  [0x0183].pack('v') + # Fill Style -> fillBackColor
7488
7289
  [0x0800004D].pack('V') +
7489
7290
 
7490
- [0x01BF].pack('v') + # Fill Style -> fNoFillHitTest
7291
+ [0x01BF].pack('v') + # Fill Style -> fNoFillHitTest
7491
7292
  [0x00110010].pack('V') +
7492
7293
  [0x01C0].pack('v') + # Line Style -> lineColor
7493
7294
  [0x0800004D].pack('V') +
7494
7295
  [0x01FF].pack('v') + # Line Style -> fNoLineDrawDash
7495
7296
  [0x00080008].pack('V') +
7496
- [0x023F].pack('v') + # Shadow Style -> fshadowObscured
7297
+ [0x023F].pack('v') + # Shadow Style -> fshadowObscured
7497
7298
  [0x00020000].pack('V') +
7498
7299
  [0x03BF].pack('v') + # Group Shape -> fPrint
7499
7300
  [0x00080000].pack('V')
@@ -7515,21 +7316,26 @@ def store_mso_opt_filter #:nodoc:
7515
7316
  data = ''
7516
7317
  length = nil
7517
7318
 
7518
- data = [0x007F].pack('v') + # Protection -> fLockAgainstGrouping
7519
- [0x01040104].pack('V') +
7520
- [0x00BF].pack('v') + # Text -> fFitTextToShape
7521
- [0x00080008].pack('V')+
7522
- [0x01BF].pack('v') + # Fill Style -> fNoFillHitTest
7523
- [0x00010000].pack('V')+
7524
- [0x01FF].pack('v') + # Line Style -> fNoLineDrawDash
7525
- [0x00080000].pack('V')+
7526
- [0x03BF].pack('v') + # Group Shape -> fPrint
7319
+ data = store_mso_protection_and_text
7320
+ data += [0x01BF].pack('v') + # Fill Style -> fNoFillHitTest
7321
+ [0x00010000].pack('V') +
7322
+ [0x01FF].pack('v') + # Line Style -> fNoLineDrawDash
7323
+ [0x00080000].pack('V') +
7324
+ [0x03BF].pack('v') + # Group Shape -> fPrint
7527
7325
  [0x000A0000].pack('V')
7528
7326
 
7529
7327
  add_mso_generic(type, version, instance, data, length)
7530
7328
  end
7531
7329
  # private :store_mso_opt_filter
7532
7330
 
7331
+ def store_mso_protection_and_text
7332
+ [0x007F].pack('v') + # Protection -> fLockAgainstGrouping
7333
+ [0x01040104].pack('V') +
7334
+ [0x00BF].pack('v') + # Text -> fFitTextToShape
7335
+ [0x00080008].pack('V')
7336
+ end
7337
+ private :store_mso_protection_and_text
7338
+
7533
7339
  ###############################################################################
7534
7340
  #
7535
7341
  # _store_mso_client_anchor()
@@ -7618,7 +7424,6 @@ def store_obj_comment(obj_id) #:nodoc:
7618
7424
  # Pack the record.
7619
7425
  header = [record, length].pack("vv")
7620
7426
 
7621
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7622
7427
  append(header, data)
7623
7428
 
7624
7429
  end
@@ -7670,7 +7475,6 @@ def store_obj_image(obj_id) #:nodoc:
7670
7475
  # Pack the record.
7671
7476
  header = [record, length].pack('vv')
7672
7477
 
7673
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7674
7478
  append(header, data)
7675
7479
 
7676
7480
  end
@@ -7710,7 +7514,6 @@ def store_obj_chart(obj_id) #:nodoc:
7710
7514
  # Pack the record.
7711
7515
  header = [record, length].pack('vv')
7712
7516
 
7713
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7714
7517
  append(header, data)
7715
7518
 
7716
7519
  end
@@ -7771,7 +7574,6 @@ def store_obj_filter(obj_id, col) #:nodoc:
7771
7574
  # Pack the record.
7772
7575
  header = [record, length].pack('vv')
7773
7576
 
7774
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7775
7577
  append(header, data)
7776
7578
  end
7777
7579
  # private :store_obj_filter
@@ -7789,7 +7591,6 @@ def store_mso_drawing_text_box #:nodoc:
7789
7591
  data = store_mso_client_text_box()
7790
7592
  header = [record, length].pack('vv')
7791
7593
 
7792
- print "sheet #{@name} : #{__FILE__}(#{__LINE__})\n" if defined?($debug)
7793
7594
  append(header, data)
7794
7595
  end
7795
7596
  # private :store_mso_drawing_text_box
@@ -7832,7 +7633,6 @@ def store_txo(string_len, format_len = 16, rotation = 0) #:nodoc:
7832
7633
  data = [grbit, rotation, reserved, reserved,
7833
7634
  string_len, format_len, reserved].pack("vvVvvvV")
7834
7635
 
7835
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
7836
7636
  append(header, data)
7837
7637
  end
7838
7638
  # private :store_txo
@@ -7864,7 +7664,6 @@ def store_txo_continue_1(string, encoding = 0) #:nodoc:
7864
7664
  length = data.bytesize
7865
7665
  header = [record, length].pack('vv')
7866
7666
 
7867
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
7868
7667
  append(header, data)
7869
7668
  end
7870
7669
 
@@ -7873,7 +7672,6 @@ def store_txo_continue_1(string, encoding = 0) #:nodoc:
7873
7672
  length = data.bytesize
7874
7673
  header = [record, length].pack('vv')
7875
7674
 
7876
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
7877
7675
  append(header, data)
7878
7676
  end
7879
7677
  # private :store_txo_continue_1
@@ -7900,7 +7698,6 @@ def store_txo_continue_2(formats) #:nodoc:
7900
7698
  length = data.bytesize
7901
7699
  header = [record, length].pack("vv")
7902
7700
 
7903
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
7904
7701
  append(header, data)
7905
7702
  end
7906
7703
  # private :store_txo_continue_2
@@ -7947,7 +7744,6 @@ def store_note(row, col, obj_id, author = nil, author_enc = nil, visible = nil)
7947
7744
  length = data.bytesize + author.bytesize
7948
7745
  header = [record, length].pack("vv")
7949
7746
 
7950
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
7951
7747
  append(header, data, author)
7952
7748
  end
7953
7749
  # private :store_note
@@ -8027,7 +7823,7 @@ def comment_params(row, col, string, options = {}) #:nodoc:
8027
7823
 
8028
7824
  # Set the comment background colour.
8029
7825
  color = params[:color]
8030
- color = Format._get_color(color)
7826
+ color = Colors.new.get_color(color)
8031
7827
  color = 0x50 if color == 0x7FFF # Default color.
8032
7828
  params[:color] = color
8033
7829
 
@@ -8583,7 +8379,7 @@ def data_validation(*args)
8583
8379
  return -2 if check_dimensions(row2, col2, 1, 1) != 0
8584
8380
 
8585
8381
  # Check that the last parameter is a hash list.
8586
- unless param.kind_of?(Hash)
8382
+ unless param.respond_to?(:to_hash)
8587
8383
  # carp "Last parameter '$param' in data_validation() must be a hash ref";
8588
8384
  return -3
8589
8385
  end
@@ -8840,7 +8636,6 @@ def store_dval(obj_id, dv_count) #:nodoc:
8840
8636
  header = [record, length].pack('vv')
8841
8637
  data = [flags, x_coord, y_coord, obj_id, dv_count].pack('vVVVV')
8842
8638
 
8843
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
8844
8639
  append(header, data)
8845
8640
  end
8846
8641
  # private :store_dval
@@ -8879,7 +8674,7 @@ def store_dv(cells, validation_type, criteria_type, #:nodoc:
8879
8674
  str_lookup = 0 # See below.
8880
8675
 
8881
8676
  # Set the string lookup flag for 'list' validations with a string array.
8882
- if validation_type == 3 && formula_1.kind_of?(Array)
8677
+ if validation_type == 3 && formula_1.respond_to?(:to_ary)
8883
8678
  str_lookup = 1
8884
8679
  end
8885
8680
 
@@ -8926,7 +8721,6 @@ def store_dv(cells, validation_type, criteria_type, #:nodoc:
8926
8721
 
8927
8722
  header = [record, data.bytesize].pack('vv')
8928
8723
 
8929
- print "sheet #{@name} : #{__FILE__}(#{__LINE__}) \n" if defined?($debug)
8930
8724
  append(header, data)
8931
8725
  end
8932
8726
  private :store_dv
@@ -8959,7 +8753,7 @@ def pack_dv_string(string = nil, max_length = 0) #:nodoc:
8959
8753
  # Handle utf8 strings
8960
8754
  if string.encoding == Encoding::UTF_8
8961
8755
  str_length = string.gsub(/[^\Wa-zA-Z_\d]/, ' ').bytesize # jlength
8962
- string = string.encode('UTF-16LE')
8756
+ string = utf8_to_16le(string)
8963
8757
  encoding = 1
8964
8758
  end
8965
8759
 
@@ -8988,13 +8782,13 @@ def pack_dv_formula(formula = nil) #:nodoc:
8988
8782
  end
8989
8783
 
8990
8784
  # Pack a list array ref as a null separated string.
8991
- if formula.kind_of?(Array)
8785
+ if formula.respond_to?(:to_ary)
8992
8786
  formula = formula.join("\0")
8993
8787
  formula = '"' + formula + '"'
8994
8788
  end
8995
8789
 
8996
8790
  # Strip the = sign at the beginning of the formula string
8997
- formula = formula.to_s unless formula.kind_of?(String)
8791
+ formula = formula.to_s unless formula.respond_to?(:to_str)
8998
8792
  formula.sub!(/^=/, '')
8999
8793
 
9000
8794
  # Parse the formula using the parser in Formula.pm