write_xlsx 0.85.6 → 0.85.11

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d9381b5893f5bba74793716ade4ac8560af6c18953acebe9eb1b13afbc7efc5
4
- data.tar.gz: aff6349570d4111a80b991504d0e1293c6e650c793028bef340fbdcb65fb355e
3
+ metadata.gz: 89f382bd2df994369316a0422365541984f53ec084c5d3bb1c5d5a03523757a9
4
+ data.tar.gz: 363697c51b2250602fd5122aa3e9c7a6c71ec755a671e659f08f19c58b184792
5
5
  SHA512:
6
- metadata.gz: a86c39e414f965061cec64e49aa8163a8d09a0e0707ba602647377b34a1d6bbd12a702a27a8c496b3d31ac93f0b4ea9e629d48eb8c5fbce4e527b6182aefb8d4
7
- data.tar.gz: b8e18e11a09b91fc86ec2fe5d6eeeb5047e27cb1378e67b871df141084040f469deabd593076a77666d1d03564bdcdf104f7ba6476b011b8a87c54c1c74fb622
6
+ metadata.gz: c719aa61decdc25064a72704d015d8a1eea48b3a94ccb7ccaf01e99456a6521c5c4fc5a5ee738a721c1e06c4632c737cf47d14afd3830a164162a789acc6e452
7
+ data.tar.gz: 96f55161f36511ef22708a377ea647f21f4ae76c978039b0c85c32c5db55ac0330f3e4c7a0e1f030d60c3d00c0c96f6c3f045bbfd240a2e2031c8ced2b2c2945
data/Changes CHANGED
@@ -1,5 +1,20 @@
1
1
  Change history of write_xlsx rubygem.
2
2
 
3
+ 2020-10-23 v0.85.11
4
+ Added Worksheet#update_range_format_with_params
5
+
6
+ 2020-10-23 v0.85.10
7
+ Fix frozen string litterals problems in Format#set_align
8
+
9
+ 2020-09-07 v0.85.9
10
+ apply pull-request #59 and #60
11
+
12
+ 2020-09-03 v0.85.8
13
+ apply pull-request #58 and #52
14
+
15
+ 2019-06-20 v0.85.7
16
+ apply pull-request #26
17
+
3
18
  2019-02-10 v0.85.6
4
19
  Fix work well in ms windows.
5
20
 
data/README.md CHANGED
@@ -84,7 +84,7 @@ the first worksheet in an Excel XML spreadsheet called ruby.xlsx:
84
84
  ## Copyright
85
85
  Original Perl module was written by John McNamara(jmcnamara@cpan.org).
86
86
 
87
- Converted to ruby by Hideo NAKAMURA(cxn03651@msj.biglobe.ne.jp)
87
+ Converted to ruby by Hideo NAKAMURA(nakamrua.hideo@gmail.com)
88
88
  Copyright (c) 2012-2018 Hideo NAKAMURA.
89
89
 
90
90
  See LICENSE.txt for further details.
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # A simple example of how to use the write_xlsx gem to
7
+ # update format of the range of cells.
8
+ #
9
+
10
+ require 'write_xlsx'
11
+
12
+ workbook = WriteXLSX.new('update_range_format_with_params.xlsx')
13
+ worksheet = workbook.add_worksheet
14
+
15
+ common_format = workbook.add_format(align: 'center', border: 1)
16
+
17
+ table_contents = [
18
+ ['Table', 'Header', 'Contents'],
19
+ ['table', 'body', 'contents'],
20
+ ['table', 'body', 'contents'],
21
+ ['table', 'body', 'contents']
22
+ ]
23
+
24
+ worksheet.write_col(0, 0, table_contents, common_format)
25
+ worksheet.update_range_format_with_params(
26
+ 0, 0, 0, 2,
27
+ bold: 1, top: 2, bottom: 2, bg_color: 31
28
+ )
29
+ worksheet.update_range_format_with_params(0, 0, 3, 0, left: 2)
30
+ worksheet.update_range_format_with_params(0, 2, 3, 2, right: 2)
31
+ worksheet.update_range_format_with_params(3, 0, 3, 2, bottom: 2)
32
+
33
+ workbook.close
@@ -2631,7 +2631,7 @@ def write_custom_error_base(tag, values, data)
2631
2631
  end
2632
2632
 
2633
2633
  def write_num_ref_or_lit(values, data)
2634
- if values =~ /^=/ # '=Sheet1!$A$1:$A$5'
2634
+ if values.to_s =~ /^=/ # '=Sheet1!$A$1:$A$5'
2635
2635
  write_num_ref(values, data, 'num')
2636
2636
  else # [1, 2, 3]
2637
2637
  write_num_lit(values)
@@ -287,11 +287,10 @@ def set_format_properties(*properties) # :nodoc:
287
287
 
288
288
  # Create a sub to set the property.
289
289
  if value.respond_to?(:to_str) || !value.respond_to?(:+)
290
- s = "set_#{key}('#{value}')"
290
+ send("set_#{key}", value.to_s)
291
291
  else
292
- s = "set_#{key}(#{value})"
292
+ send("set_#{key}", value)
293
293
  end
294
- eval s
295
294
  end
296
295
  end
297
296
  end
@@ -507,7 +506,7 @@ def self.color(color_code)
507
506
  def set_align(location)
508
507
  return unless location # No default
509
508
 
510
- location.downcase!
509
+ location = location.downcase
511
510
 
512
511
  set_text_h_align(1) if location == 'left'
513
512
  set_text_h_align(2) if location == 'centre'
@@ -306,7 +306,7 @@ def range_start_cell_for_conditional_formatting(*args) # :nodoc:
306
306
 
307
307
  def row_col_param_for_conditional_formatting(*args)
308
308
  # Check for a cell reference in A1 notation and substitute row and column
309
- if args[0] =~ /^\D/
309
+ if args[0].to_s =~ /^\D/
310
310
  # Check for a user defined multiple range like B3:K6,B8:K11.
311
311
  user_range = args[0].sub(/^=/, '').gsub(/\s*,\s*/, ' ').gsub(/\$/, '') if args[0] =~ /,/
312
312
  end
@@ -383,7 +383,7 @@ def check_conditional_formatting_parameters(param) # :nodoc:
383
383
  end
384
384
 
385
385
  def convert_date_time_if_required(val)
386
- if val =~ /T/
386
+ if val.to_s =~ /T/
387
387
  date_time = convert_date_time(val)
388
388
  raise "Invalid date/time value '#{val}' in conditional_formatting()" unless date_time
389
389
  date_time
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
  require 'write_xlsx/package/xml_writer_simple'
3
4
  require 'write_xlsx/utility'
4
5
 
@@ -8,29 +9,33 @@ class SharedStrings
8
9
 
9
10
  include Writexlsx::Utility
10
11
 
12
+ PRESERVE_SPACE_ATTRIBUTES = ['xml:space', 'preserve'].freeze
13
+
11
14
  def initialize
12
- @writer = Package::XMLWriterSimple.new
13
- @strings = [] # string table
14
- @count = {} # => count
15
+ @writer = Package::XMLWriterSimple.new
16
+ @strings = [] # string table
17
+ @strings_index = {} # string table index
18
+ @count = 0 # count
15
19
  end
16
20
 
17
21
  def index(string, params = {})
18
22
  add(string) unless params[:only_query]
19
- @strings.index(string)
23
+ @strings_index[string]
20
24
  end
21
25
 
22
26
  def add(string)
23
- str = string.dup
24
- if @count[str]
25
- @count[str] += 1
26
- else
27
+ unless @strings_index[string]
28
+ # Only first time the string will be append to list
29
+ # next time we only check and not #dup it
30
+ str = string.dup.freeze
27
31
  @strings << str
28
- @count[str] = 1
32
+ @strings_index[str] = @strings.size - 1
29
33
  end
34
+ @count += 1
30
35
  end
31
36
 
32
37
  def string(index)
33
- @strings[index].dup
38
+ @strings[index]
34
39
  end
35
40
 
36
41
  def empty?
@@ -77,7 +82,6 @@ def write_sst_strings
77
82
  # Write the <si> element.
78
83
  #
79
84
  def write_si(string)
80
- string = string.dup
81
85
  attributes = []
82
86
 
83
87
  # Excel escapes control characters with _xHHHH_ and also escapes any
@@ -100,7 +104,7 @@ def write_si(string)
100
104
  end
101
105
 
102
106
  # Add attribute to preserve leading or trailing whitespace.
103
- attributes << ['xml:space', 'preserve'] if string =~ /\A\s|\s\Z/
107
+ attributes << PRESERVE_SPACE_ATTRIBUTES if string =~ /\A\s|\s\Z/
104
108
 
105
109
  # Write any rich strings without further tags.
106
110
  if string =~ %r{^<r>} && string =~ %r{</r>$}
@@ -120,7 +124,7 @@ def add_c2_c3(string)
120
124
  end
121
125
 
122
126
  def total_count
123
- @count.values.inject(0) { |sum, count| sum += count }
127
+ @count
124
128
  end
125
129
 
126
130
  def unique_count
@@ -49,7 +49,7 @@ def set_style_properties(xf_formats, palette, font_count, num_format_count, bord
49
49
  # based on the default or user defined values in the Workbook palette.
50
50
  #
51
51
  def palette_color(index)
52
- if index =~ /^#([0-9A-F]{6})$/i
52
+ if index.to_s =~ /^#([0-9A-F]{6})$/i
53
53
  "FF#{$1.upcase}"
54
54
  else
55
55
  "FF#{super(index)}"
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
  #
3
4
  # XMLWriterSimple
4
5
  #
@@ -29,10 +30,9 @@ def tag_elements(tag, attributes = [])
29
30
  end
30
31
 
31
32
  def tag_elements_str(tag, attributes = [])
32
- str = ''
33
- str << start_tag_str(tag, attributes)
34
- str << yield
35
- str << end_tag_str(tag)
33
+ str = start_tag_str(tag, attributes) +
34
+ yield +
35
+ end_tag_str(tag)
36
36
  end
37
37
 
38
38
  def start_tag(tag, attr = [])
@@ -65,7 +65,7 @@ def empty_tag_encoded_str(tag, attr = [])
65
65
  end
66
66
 
67
67
  def data_element(tag, data, attr = [])
68
- tag_elements(tag, attr) { io_write("#{escape_data(data)}") }
68
+ tag_elements(tag, attr) { io_write(escape_data(data)) }
69
69
  end
70
70
 
71
71
  #
@@ -118,7 +118,7 @@ def key_vals(attribute)
118
118
  end
119
119
 
120
120
  def escape_attributes(str = '')
121
- return str if !(str =~ /["&<>]/)
121
+ return str if !(str.to_s =~ /["&<>]/)
122
122
 
123
123
  str.
124
124
  gsub(/&/, "&amp;").
@@ -128,7 +128,7 @@ def escape_attributes(str = '')
128
128
  end
129
129
 
130
130
  def escape_data(str = '')
131
- if str =~ /[&<>]/
131
+ if str.to_s =~ /[&<>]/
132
132
  str.gsub(/&/, '&amp;').
133
133
  gsub(/</, '&lt;').
134
134
  gsub(/>/, '&gt;')
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
  require 'write_xlsx/col_name'
3
4
 
4
5
  module Writexlsx
@@ -243,7 +244,7 @@ def put_deprecate_message(method)
243
244
 
244
245
  # Check for a cell reference in A1 notation and substitute row and column
245
246
  def row_col_notation(args) # :nodoc:
246
- if args[0] =~ /^\D/
247
+ if args[0].to_s =~ /^\D/
247
248
  substitute_cellref(*args)
248
249
  else
249
250
  args
@@ -303,11 +304,12 @@ def write_color(writer, name, value) #:nodoc:
303
304
  writer.empty_tag('color', attributes)
304
305
  end
305
306
 
307
+ PERL_TRUE_VALUES = [false, nil, 0, "0", "", [], {}].freeze
306
308
  #
307
309
  # return perl's boolean result
308
310
  #
309
311
  def ptrue?(value)
310
- if [false, nil, 0, "0", "", [], {}].include?(value)
312
+ if PERL_TRUE_VALUES.include?(value)
311
313
  false
312
314
  else
313
315
  true
@@ -1 +1 @@
1
- WriteXLSX_VERSION = "0.85.6"
1
+ WriteXLSX_VERSION = "0.85.11"
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
  require 'write_xlsx/package/xml_writer_simple'
3
4
  require 'write_xlsx/package/packager'
4
5
  require 'write_xlsx/sheets'
@@ -926,7 +927,7 @@ def set_calc_mode(mode, calc_id = nil)
926
927
  #
927
928
  def set_custom_color(index, red = 0, green = 0, blue = 0)
928
929
  # Match a HTML #xxyyzz style parameter
929
- if red =~ /^#(\w\w)(\w\w)(\w\w)/
930
+ if red.to_s =~ /^#(\w\w)(\w\w)(\w\w)/
930
931
  red = $1.hex
931
932
  green = $2.hex
932
933
  blue = $3.hex
@@ -972,8 +973,9 @@ def date_1904? #:nodoc:
972
973
  # Add a string to the shared string table, if it isn't already there, and
973
974
  # return the string index.
974
975
  #
975
- def shared_string_index(str, params = {}) #:nodoc:
976
- @shared_strings.index(str, params)
976
+ EMPTY_HASH = {}.freeze
977
+ def shared_string_index(str) #:nodoc:
978
+ @shared_strings.index(str, EMPTY_HASH)
977
979
  end
978
980
 
979
981
  def str_unique # :nodoc:
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
  require 'write_xlsx/package/xml_writer_simple'
3
4
  require 'write_xlsx/package/button'
4
5
  require 'write_xlsx/colors'
@@ -720,7 +721,7 @@ def protect_default_settings # :nodoc:
720
721
  #
721
722
  def set_column(*args)
722
723
  # Check for a cell reference in A1 notation and substitute row and column
723
- if args[0] =~ /^\D/
724
+ if args[0].to_s =~ /^\D/
724
725
  row1, firstcol, row2, lastcol, *data = substitute_cellref(*args)
725
726
  else
726
727
  firstcol, lastcol, *data = args
@@ -2188,7 +2189,7 @@ def write_comment(*args)
2188
2189
  def write_number(*args)
2189
2190
  # Check for a cell reference in A1 notation and substitute row and column
2190
2191
  row, col, num, xf = row_col_notation(args)
2191
- raise WriteXLSXInsufficientArgumentError if [row, col, num].include?(nil)
2192
+ raise WriteXLSXInsufficientArgumentError if row.nil? || col.nil? || num.nil?
2192
2193
 
2193
2194
  # Check that row and col are valid and store max and min values
2194
2195
  check_dimensions(row, col)
@@ -2230,13 +2231,13 @@ def write_string(*args)
2230
2231
  # Check for a cell reference in A1 notation and substitute row and column
2231
2232
  row, col, str, xf = row_col_notation(args)
2232
2233
  str &&= str.to_s
2233
- raise WriteXLSXInsufficientArgumentError if [row, col, str].include?(nil)
2234
+ raise WriteXLSXInsufficientArgumentError if row.nil? || col.nil? || str.nil?
2234
2235
 
2235
2236
  # Check that row and col are valid and store max and min values
2236
2237
  check_dimensions(row, col)
2237
2238
  store_row_col_max_min_values(row, col)
2238
2239
 
2239
- index = shared_string_index(str[0, STR_MAX])
2240
+ index = shared_string_index(str.length > STR_MAX ? str[0, STR_MAX] : str)
2240
2241
 
2241
2242
  store_data_to_table(StringCellData.new(self, row, col, index, xf))
2242
2243
  end
@@ -2527,6 +2528,91 @@ def write_array_formula(*args)
2527
2528
  end
2528
2529
  end
2529
2530
 
2531
+ #
2532
+ # :call-seq:
2533
+ # update_format_with_params(row, col, format_params)
2534
+ #
2535
+ # Update formatting of the cell to the specified row and column (zero indexed).
2536
+ #
2537
+ # worksheet.update_format_with_params(0, 0, color: 'red')
2538
+ #
2539
+ # This method is used to update formatting of the cell keeping cell contents
2540
+ # and formatting.
2541
+ #
2542
+ # If the cell doesn't have CellData object, this method create a CellData
2543
+ # using write_blank method.
2544
+ # If the cell has CellData, this method fetch contents and format of cell from
2545
+ # the CellData object and recreate CellData using write method.
2546
+ #
2547
+ def update_format_with_params(*args)
2548
+ row, col, params = row_col_notation(args)
2549
+ raise WriteXLSXInsufficientArgumentError if row.nil? || col.nil? || params.nil?
2550
+
2551
+ # Check that row and col are valid and store max and min values
2552
+ check_dimensions(row, col)
2553
+ store_row_col_max_min_values(row, col)
2554
+
2555
+ format = nil
2556
+ cell_data = nil
2557
+ if @cell_data_table[row].nil? || @cell_data_table[row][col].nil?
2558
+ format = @workbook.add_format(params)
2559
+ write_blank(row, col, format)
2560
+ else
2561
+ if @cell_data_table[row][col].xf.nil?
2562
+ format = @workbook.add_format(params)
2563
+ cell_data = @cell_data_table[row][col]
2564
+ else
2565
+ format = @workbook.add_format
2566
+ cell_data = @cell_data_table[row][col]
2567
+ format.copy(cell_data.xf)
2568
+ format.set_format_properties(params)
2569
+ end
2570
+ # keep original value of cell
2571
+ if cell_data.is_a? FormulaCellData
2572
+ value = "=#{cell_data.token}"
2573
+ elsif cell_data.is_a? FormulaArrayCellData
2574
+ value = "{=#{cell_data.token}}"
2575
+ elsif cell_data.is_a? StringCellData
2576
+ value = @workbook.shared_strings.string(cell_data.data[:sst_id])
2577
+ else
2578
+ value = cell_data.data
2579
+ end
2580
+ write(row, col, value, format)
2581
+ end
2582
+ end
2583
+
2584
+ #
2585
+ # :call-seq:
2586
+ # update_range_format_with_params(row_first, col_first, row_last, col_last, format_params)
2587
+ #
2588
+ # Update formatting of cells in range to the specified row and column (zero indexed).
2589
+ #
2590
+ # worksheet.update_range_format_with_params(0, 0, 3, 3, color: 'red')
2591
+ #
2592
+ # This method is used to update formatting of multiple cells keeping cells' contents
2593
+ # and formatting.
2594
+ #
2595
+ #
2596
+ def update_range_format_with_params(*args)
2597
+ row_first, col_first, row_last, col_last, params = row_col_notation(args)
2598
+
2599
+ raise WriteXLSXInsufficientArgumentError if [row_first, col_first, row_last, col_last, params].include?(nil)
2600
+
2601
+ # Swap last row/col with first row/col as necessary
2602
+ row_first, row_last = row_last, row_first if row_first > row_last
2603
+ col_first, col_last = col_last, col_first if col_first > col_last
2604
+
2605
+ # Check that column number is valid and store the max value
2606
+ check_dimensions(row_last, col_last)
2607
+ store_row_col_max_min_values(row_last, col_last)
2608
+
2609
+ (row_first..row_last).each do |row|
2610
+ (col_first..col_last).each do |col|
2611
+ update_format_with_params(row, col, params)
2612
+ end
2613
+ end
2614
+ end
2615
+
2530
2616
  #
2531
2617
  # The outline_settings() method is used to control the appearance of
2532
2618
  # outlines in Excel. Outlines are described in
@@ -5810,7 +5896,7 @@ def excel2003_style? # :nodoc:
5810
5896
  # based on the default or user defined values in the Workbook palette.
5811
5897
  #
5812
5898
  def palette_color(index) #:nodoc:
5813
- if index =~ /^#([0-9A-F]{6})$/i
5899
+ if index.to_s =~ /^#([0-9A-F]{6})$/i
5814
5900
  "FF#{$1.upcase}"
5815
5901
  else
5816
5902
  "FF#{super(index)}"
@@ -6099,7 +6185,7 @@ def parse_filter_tokens(expression, tokens) #:nodoc:
6099
6185
  # Special handling of "Top" filter expressions.
6100
6186
  if tokens[0] =~ /^top|bottom$/i
6101
6187
  value = tokens[1]
6102
- if (value =~ /\D/ or value.to_i < 1 or value.to_i > 500)
6188
+ if (value.to_s =~ /\D/ or value.to_i < 1 or value.to_i > 500)
6103
6189
  raise "The value '#{value}' in expression '#{expression}' " +
6104
6190
  "must be in the range 1 to 500"
6105
6191
  end
@@ -6128,7 +6214,7 @@ def parse_filter_tokens(expression, tokens) #:nodoc:
6128
6214
  end
6129
6215
 
6130
6216
  # Special handling for Blanks/NonBlanks.
6131
- if (token =~ /^blanks|nonblanks$/i)
6217
+ if (token.to_s =~ /^blanks|nonblanks$/i)
6132
6218
  # Only allow Equals or NotEqual in this context.
6133
6219
  if (operator != 2 and operator != 5)
6134
6220
  raise "The operator '#{tokens[1]}' in expression '#{expression}' " +
@@ -6156,7 +6242,7 @@ def parse_filter_tokens(expression, tokens) #:nodoc:
6156
6242
 
6157
6243
  # if the string token contains an Excel match character then change the
6158
6244
  # operator type to indicate a non "simple" equality.
6159
- if (operator == 2 and token =~ /[*?]/)
6245
+ if (operator == 2 and token.to_s =~ /[*?]/)
6160
6246
  operator = 22
6161
6247
  end
6162
6248
 
@@ -7510,8 +7596,8 @@ def calc_spans(data, row_num, span_min, span_max)
7510
7596
  # Add a string to the shared string table, if it isn't already there, and
7511
7597
  # return the string index.
7512
7598
  #
7513
- def shared_string_index(str, params = {}) #:nodoc:
7514
- @workbook.shared_string_index(str, params)
7599
+ def shared_string_index(str) #:nodoc:
7600
+ @workbook.shared_string_index(str)
7515
7601
  end
7516
7602
 
7517
7603
  #
@@ -7634,7 +7720,7 @@ def set_active_pane_and_cell_selections(row, col, top_row, left_col, active_cell
7634
7720
 
7635
7721
  def prepare_filter_column(col) # :nodoc:
7636
7722
  # Check for a column reference in A1 notation and substitute.
7637
- if col =~ /^\D/
7723
+ if col.to_s =~ /^\D/
7638
7724
  col_letter = col
7639
7725
 
7640
7726
  # Convert col ref to a cell ref and then to a col number.
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Writexlsx
4
5
  class Worksheet
@@ -63,9 +64,10 @@ def data
63
64
  { :sst_id => token }
64
65
  end
65
66
 
67
+ TYPE_STR_ATTRS = ['t', 's'].freeze
66
68
  def write_cell
67
69
  attributes = cell_attributes
68
- attributes << ['t', 's']
70
+ attributes << TYPE_STR_ATTRS
69
71
  @worksheet.writer.tag_elements('c', attributes) do
70
72
  @worksheet.write_cell_value(token)
71
73
  end
@@ -282,7 +282,7 @@ def valid_criteria_type # :nodoc:
282
282
 
283
283
  def convert_date_time_value(key) # :nodoc:
284
284
  value = instance_variable_get("@#{key}")
285
- if value && value =~ /T/
285
+ if value && value.to_s =~ /T/
286
286
  date_time = convert_date_time(value)
287
287
  instance_variable_set("@#{key}", date_time) if date_time
288
288
  date_time
@@ -24,7 +24,7 @@ def initialize(url, str, tip)
24
24
  str ||= url.dup
25
25
 
26
26
  # Strip the mailto header.
27
- str.sub!(/^mailto:/, '')
27
+ normalized_str = str.sub(/^mailto:/, '')
28
28
 
29
29
  # Escape URL unless it looks already escaped.
30
30
  url = escape_url(url)
@@ -35,7 +35,7 @@ def initialize(url, str, tip)
35
35
  end
36
36
 
37
37
  @url = url
38
- @str = str
38
+ @str = normalized_str
39
39
  @url_str = nil
40
40
  @tip = tip
41
41
  end
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestUpdateRangeFormatWithParams < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ @tempfile.close(true)
11
+ end
12
+
13
+ def test_update_range_format_with_params
14
+ @xlsx = 'update_range_format_with_params.xlsx'
15
+ workbook = WriteXLSX.new(@io)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ common_format = workbook.add_format(align: 'center', border: 1)
19
+
20
+ table_contents = [
21
+ ['Table', 'Header', 'Contents'],
22
+ ['table', 'body', 'contents'],
23
+ ['table', 'body', 'contents'],
24
+ ['table', 'body', 'contents']
25
+ ]
26
+
27
+ worksheet.write_col(0, 0, table_contents, common_format)
28
+ worksheet.update_range_format_with_params(
29
+ 0, 0, 0, 2,
30
+ bold: 1, top: 2, bottom: 2, bg_color: 31
31
+ )
32
+ worksheet.update_range_format_with_params(0, 0, 3, 0, left: 2)
33
+ worksheet.update_range_format_with_params(0, 2, 3, 2, right: 2)
34
+ worksheet.update_range_format_with_params(3, 0, 3, 2, bottom: 2)
35
+
36
+ workbook.close
37
+ compare_for_regression(
38
+ nil,
39
+ {'xl/workbook.xml' => ['<workbookView']}
40
+ )
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
2
+ lib_dir = File.join(base_dir, "lib")
3
+ test_dir = File.join(base_dir, "test")
4
+
5
+ $LOAD_PATH.unshift(lib_dir)
6
+
7
+ require 'test/unit'
8
+
9
+ exit Test::Unit::AutoRunner.run(true, test_dir)
@@ -23,11 +23,11 @@ def test_empty_tag_with_xml_decl
23
23
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
24
24
  <foo/>
25
25
  EOS
26
- assert_equal(expected, @obj.xml_decl << @obj.empty_tag('foo') << "\n")
26
+ assert_equal(expected, @obj.xml_decl + @obj.empty_tag('foo') + "\n")
27
27
  end
28
28
 
29
29
  def test_start_end_tag
30
- assert_equal("<foo></foo>", @obj.start_tag('foo') << @obj.end_tag('foo'))
30
+ assert_equal("<foo></foo>", @obj.start_tag('foo') + @obj.end_tag('foo'))
31
31
  end
32
32
 
33
33
  def test_attribute
@@ -39,7 +39,7 @@ def test_attribute
39
39
  def test_character_data
40
40
  assert_equal(
41
41
  "<foo>&lt;tag&gt;&amp;amp;&lt;/tag&gt;</foo>",
42
- @obj.start_tag('foo') << @obj.characters("<tag>&amp;</tag>") << @obj.end_tag('foo')
42
+ @obj.start_tag('foo') + @obj.characters("<tag>&amp;</tag>") + @obj.end_tag('foo')
43
43
  )
44
44
  end
45
45
 
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+ require 'write_xlsx'
4
+ require 'stringio'
5
+
6
+ class TestFormat < Test::Unit::TestCase
7
+ def setup
8
+ @workbook = WriteXLSX.new(StringIO.new)
9
+ @format = @workbook.add_format
10
+ end
11
+
12
+ def test_set_align_with_frozen_parameter
13
+ assert_nothing_raised do
14
+ @format.set_align('LEFT'.freeze)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,111 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+ require 'write_xlsx'
4
+ require 'stringio'
5
+
6
+ class TestUpdateFormatMethods < Test::Unit::TestCase
7
+ def setup
8
+ @workbook = WriteXLSX.new(StringIO.new)
9
+ @worksheet = @workbook.add_worksheet('')
10
+ end
11
+
12
+ def test_update_format_with_params_with_insufficient_args_raise_InsufficientArgumentError
13
+ assert_raise(WriteXLSXInsufficientArgumentError) do
14
+ @worksheet.update_format_with_params
15
+ end
16
+ assert_raise(WriteXLSXInsufficientArgumentError) do
17
+ @worksheet.update_format_with_params(0)
18
+ end
19
+ assert_raise(WriteXLSXInsufficientArgumentError) do
20
+ @worksheet.update_format_with_params('A1')
21
+ end
22
+ end
23
+
24
+ def test_update_format_with_params_with_valid_arg_not_raise
25
+ assert_nothing_raised do
26
+ @worksheet.update_format_with_params(0, 0, color: 'red', border: 2)
27
+ end
28
+ assert_nothing_raised do
29
+ @worksheet.update_format_with_params('B2', align: 'center')
30
+ end
31
+ end
32
+
33
+ def test_update_format_with_params_should_write_blank_when_there_is_no_CellData
34
+ assert_nil(@worksheet.instance_variable_get(:@cell_data_table)[0])
35
+ @worksheet.update_format_with_params(0, 0, left: 4)
36
+ assert @worksheet.instance_variable_get(:@cell_data_table)[0][0] != nil
37
+ end
38
+
39
+ def test_update_format_with_params_should_keep_data_when_updating_format
40
+ number = 153
41
+ @worksheet.write(0, 0, number)
42
+ @worksheet.update_format_with_params(0, 0, bg_color: 'gray')
43
+ assert_equal(@worksheet.instance_variable_get(:@cell_data_table)[0][0].data, number)
44
+
45
+ string = 'Hello, World!'
46
+ @worksheet.write(0, 0, string)
47
+ @worksheet.update_format_with_params(0, 0, bg_color: 'gray')
48
+ written_string = @workbook.shared_strings.string(@worksheet.instance_variable_get(:@cell_data_table)[0][0].data[:sst_id])
49
+ assert_equal(written_string, string)
50
+
51
+ formula = '=1+1'
52
+ @worksheet.write(0, 0, formula)
53
+ @worksheet.update_format_with_params(0, 0, bg_color: 'gray')
54
+ assert_equal(@worksheet.instance_variable_get(:@cell_data_table)[0][0].token, '1+1')
55
+
56
+ array_formula = '{=SUM(B1:C1*B2:C2)}'
57
+ @worksheet.write('A1', array_formula)
58
+ @worksheet.update_format_with_params(0, 0, bg_color: 'gray')
59
+ assert_equal(@worksheet.instance_variable_get(:@cell_data_table)[0][0].token, 'SUM(B1:C1*B2:C2)')
60
+
61
+ url = 'https://www.writexlsx.io'
62
+ @worksheet.write(0, 0, url)
63
+ @worksheet.update_format_with_params(0, 0, bg_color: 'gray')
64
+ written_string = @workbook.shared_strings.string(@worksheet.instance_variable_get(:@cell_data_table)[0][0].data[:sst_id])
65
+ assert_equal(written_string, url)
66
+
67
+ string = 'Hello, World!'
68
+ format = @workbook.add_format(color: 'white')
69
+ @worksheet.write(0, 0, string, format)
70
+ @worksheet.update_format_with_params(0, 0, bg_color: 'gray')
71
+ written_string = @workbook.shared_strings.string(@worksheet.instance_variable_get(:@cell_data_table)[0][0].data[:sst_id])
72
+ assert_equal(written_string, string)
73
+ end
74
+
75
+ def test_update_format_with_params_should_not_update_other_cells_format
76
+ format = @workbook.add_format(bold: 1)
77
+ @worksheet.write_row(0, 0, ['', '', '', '', ''], format)
78
+ @worksheet.update_format_with_params(0, 0, bold: 0)
79
+ assert_not_equal(@worksheet.instance_variable_get(:@cell_data_table)[0][0].xf,
80
+ @worksheet.instance_variable_get(:@cell_data_table)[0][1].xf )
81
+ assert_equal(@worksheet.instance_variable_get(:@cell_data_table)[0][0].xf.bold, 0)
82
+ assert_equal(@worksheet.instance_variable_get(:@cell_data_table)[0][1].xf.bold, 1)
83
+ end
84
+
85
+ def test_update_range_format_with_params_with_insufficient_args_raise_InsufficientArgumentError
86
+ assert_raise(WriteXLSXInsufficientArgumentError) do
87
+ @worksheet.update_range_format_with_params
88
+ end
89
+ assert_raise(WriteXLSXInsufficientArgumentError) do
90
+ @worksheet.update_range_format_with_params(0, 0)
91
+ end
92
+ assert_raise(WriteXLSXInsufficientArgumentError) do
93
+ @worksheet.update_range_format_with_params('A1')
94
+ end
95
+ assert_raise(WriteXLSXInsufficientArgumentError) do
96
+ @worksheet.update_range_format_with_params(0, 0, 3, 3)
97
+ end
98
+ assert_raise(WriteXLSXInsufficientArgumentError) do
99
+ @worksheet.update_range_format_with_params('A2:C2')
100
+ end
101
+ end
102
+
103
+ def test_update_range_format_with_params_with_valid_arg_not_raise
104
+ assert_nothing_raised do
105
+ @worksheet.update_range_format_with_params(0, 0, 3, 3, bold: 1)
106
+ end
107
+ assert_nothing_raised do
108
+ @worksheet.update_range_format_with_params('A2:D5', bold: 1)
109
+ end
110
+ end
111
+ end
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.name = "write_xlsx"
8
8
  gem.version = WriteXLSX_VERSION
9
9
  gem.authors = ["Hideo NAKAMURA"]
10
- gem.email = ["cxn03651@msj.biglobe.ne.jp"]
10
+ gem.email = ["nakamura.hideo@gmail.com"]
11
11
  gem.description = "write_xlsx is a gem to create a new file in the Excel 2007+ XLSX format."
12
12
  gem.summary = "write_xlsx is a gem to create a new file in the Excel 2007+ XLSX format."
13
13
  gem.homepage = "http://github.com/cxn03651/write_xlsx#readme"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: write_xlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.85.6
4
+ version: 0.85.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hideo NAKAMURA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-10 00:00:00.000000000 Z
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: '0'
69
69
  description: write_xlsx is a gem to create a new file in the Excel 2007+ XLSX format.
70
70
  email:
71
- - cxn03651@msj.biglobe.ne.jp
71
+ - nakamura.hideo@gmail.com
72
72
  executables:
73
73
  - extract_vba.rb
74
74
  extensions: []
@@ -154,6 +154,7 @@ files:
154
154
  - examples/stocks.rb
155
155
  - examples/tab_colors.rb
156
156
  - examples/tables.rb
157
+ - examples/update_range_format_with_params.rb
157
158
  - examples/vbaProject.bin
158
159
  - lib/write_xlsx.rb
159
160
  - lib/write_xlsx/chart.rb
@@ -978,6 +979,7 @@ files:
978
979
  - test/regression/test_tutorial01.rb
979
980
  - test/regression/test_tutorial02.rb
980
981
  - test/regression/test_tutorial03.rb
982
+ - test/regression/test_update_range_format_with_params.rb
981
983
  - test/regression/test_urls_as_strings.rb
982
984
  - test/regression/test_utf8_01.rb
983
985
  - test/regression/test_utf8_03.rb
@@ -1561,6 +1563,7 @@ files:
1561
1563
  - test/regression/xlsx_files/tutorial01.xlsx
1562
1564
  - test/regression/xlsx_files/tutorial02.xlsx
1563
1565
  - test/regression/xlsx_files/tutorial03.xlsx
1566
+ - test/regression/xlsx_files/update_range_format_with_params.xlsx
1564
1567
  - test/regression/xlsx_files/urls_as_strings.xlsx
1565
1568
  - test/regression/xlsx_files/utf8_01.xlsx
1566
1569
  - test/regression/xlsx_files/utf8_03.xlsx
@@ -1578,6 +1581,7 @@ files:
1578
1581
  - test/regression/xlsx_files/vml03.xlsx
1579
1582
  - test/regression/xlsx_files/vml04.xlsx
1580
1583
  - test/republic.png
1584
+ - test/run_test.rb
1581
1585
  - test/test_col_name.rb
1582
1586
  - test/test_delete_files.rb
1583
1587
  - test/test_example_match.rb
@@ -1620,6 +1624,7 @@ files:
1620
1624
  - test/worksheet/test_convert_date_time_03.rb
1621
1625
  - test/worksheet/test_convert_date_time_04.rb
1622
1626
  - test/worksheet/test_extract_filter_tokens.rb
1627
+ - test/worksheet/test_format.rb
1623
1628
  - test/worksheet/test_parse_filter_expression.rb
1624
1629
  - test/worksheet/test_position_object.rb
1625
1630
  - test/worksheet/test_repeat_formula.rb
@@ -1634,6 +1639,7 @@ files:
1634
1639
  - test/worksheet/test_sparkline_09.rb
1635
1640
  - test/worksheet/test_sparkline_10.rb
1636
1641
  - test/worksheet/test_sparkline_11.rb
1642
+ - test/worksheet/test_update_format_methods.rb
1637
1643
  - test/worksheet/test_worksheet_01.rb
1638
1644
  - test/worksheet/test_worksheet_02.rb
1639
1645
  - test/worksheet/test_worksheet_03.rb
@@ -1709,8 +1715,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1709
1715
  - !ruby/object:Gem::Version
1710
1716
  version: '0'
1711
1717
  requirements: []
1712
- rubyforge_project:
1713
- rubygems_version: 2.7.6
1718
+ rubygems_version: 3.0.3
1714
1719
  signing_key:
1715
1720
  specification_version: 4
1716
1721
  summary: write_xlsx is a gem to create a new file in the Excel 2007+ XLSX format.
@@ -2490,6 +2495,7 @@ test_files:
2490
2495
  - test/regression/test_tutorial01.rb
2491
2496
  - test/regression/test_tutorial02.rb
2492
2497
  - test/regression/test_tutorial03.rb
2498
+ - test/regression/test_update_range_format_with_params.rb
2493
2499
  - test/regression/test_urls_as_strings.rb
2494
2500
  - test/regression/test_utf8_01.rb
2495
2501
  - test/regression/test_utf8_03.rb
@@ -3073,6 +3079,7 @@ test_files:
3073
3079
  - test/regression/xlsx_files/tutorial01.xlsx
3074
3080
  - test/regression/xlsx_files/tutorial02.xlsx
3075
3081
  - test/regression/xlsx_files/tutorial03.xlsx
3082
+ - test/regression/xlsx_files/update_range_format_with_params.xlsx
3076
3083
  - test/regression/xlsx_files/urls_as_strings.xlsx
3077
3084
  - test/regression/xlsx_files/utf8_01.xlsx
3078
3085
  - test/regression/xlsx_files/utf8_03.xlsx
@@ -3090,6 +3097,7 @@ test_files:
3090
3097
  - test/regression/xlsx_files/vml03.xlsx
3091
3098
  - test/regression/xlsx_files/vml04.xlsx
3092
3099
  - test/republic.png
3100
+ - test/run_test.rb
3093
3101
  - test/test_col_name.rb
3094
3102
  - test/test_delete_files.rb
3095
3103
  - test/test_example_match.rb
@@ -3132,6 +3140,7 @@ test_files:
3132
3140
  - test/worksheet/test_convert_date_time_03.rb
3133
3141
  - test/worksheet/test_convert_date_time_04.rb
3134
3142
  - test/worksheet/test_extract_filter_tokens.rb
3143
+ - test/worksheet/test_format.rb
3135
3144
  - test/worksheet/test_parse_filter_expression.rb
3136
3145
  - test/worksheet/test_position_object.rb
3137
3146
  - test/worksheet/test_repeat_formula.rb
@@ -3146,6 +3155,7 @@ test_files:
3146
3155
  - test/worksheet/test_sparkline_09.rb
3147
3156
  - test/worksheet/test_sparkline_10.rb
3148
3157
  - test/worksheet/test_sparkline_11.rb
3158
+ - test/worksheet/test_update_format_methods.rb
3149
3159
  - test/worksheet/test_worksheet_01.rb
3150
3160
  - test/worksheet/test_worksheet_02.rb
3151
3161
  - test/worksheet/test_worksheet_03.rb