write_xlsx 1.11.2 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -113,7 +113,8 @@ module Writexlsx
113
113
  @drawing_rels_id = 0
114
114
  @vml_drawing_rels = {}
115
115
  @vml_drawing_rels_id = 0
116
- @has_dynamic_arrays = false
116
+ @has_dynamic_functions = false
117
+ @has_embedded_images = false
117
118
 
118
119
  @use_future_functions = false
119
120
 
@@ -160,6 +161,8 @@ module Writexlsx
160
161
  @page_setup.margin_footer = 0.5
161
162
  @page_setup.header_footer_aligns = false
162
163
  end
164
+
165
+ @embedded_image_indexes = @workbook.embedded_image_indexes
163
166
  end
164
167
 
165
168
  def set_xml_writer(filename) # :nodoc:
@@ -1446,6 +1449,7 @@ module Writexlsx
1446
1449
  formula = expand_formula(formula, 'HYPGEOM.DIST\(')
1447
1450
  formula = expand_formula(formula, 'IFNA\(')
1448
1451
  formula = expand_formula(formula, 'IFS\(')
1452
+ formula = expand_formula(formula, 'IMAGE\(')
1449
1453
  formula = expand_formula(formula, 'IMCOSH\(')
1450
1454
  formula = expand_formula(formula, 'IMCOT\(')
1451
1455
  formula = expand_formula(formula, 'IMCSCH\(')
@@ -1536,7 +1540,7 @@ module Writexlsx
1536
1540
  raise WriteXLSXInsufficientArgumentError if [_row, _col, _formula].include?(nil)
1537
1541
 
1538
1542
  # Check for dynamic array functions.
1539
- regex = /\bLET\(|\bSORT\(|\bLAMBDA\(|\bSINGLE\(|\bSORTBY\(|\bUNIQUE\(|\bXMATCH\(|\bFILTER\(|\bXLOOKUP\(|\bSEQUENCE\(|\bRANDARRAY\(|\bANCHORARRAY\(/
1543
+ regex = /\bANCHORARRAY\(|\bBYCOL\(|\bBYROW\(|\bCHOOSECOLS\(|\bCHOOSEROWS\(|\bDROP\(|\bEXPAND\(|\bFILTER\(|\bHSTACK\(|\bLAMBDA\(|\bMAKEARRAY\(|\bMAP\(|\bRANDARRAY\(|\bREDUCE\(|\bSCAN\(|\bSEQUENCE\(|\bSINGLE\(|\bSORT\(|\bSORTBY\(|\bSWITCH\(|\bTAKE\(|\bTEXTSPLIT\(|\bTOCOL\(|\bTOROW\(|\bUNIQUE\(|\bVSTACK\(|\bWRAPCOLS\(|\bWRAPROWS\(|\bXLOOKUP\(/
1540
1544
  if _formula =~ regex
1541
1545
  return write_dynamic_array_formula(
1542
1546
  _row, _col, _row, _col, _formula, _format, _value
@@ -1549,7 +1553,7 @@ module Writexlsx
1549
1553
  else
1550
1554
  check_dimensions(_row, _col)
1551
1555
  store_row_col_max_min_values(_row, _col)
1552
- _formula = _formula.sub(/^=/, '')
1556
+ _formula = prepare_formula(_formula)
1553
1557
 
1554
1558
  store_data_to_table(FormulaCellData.new(_formula, _format, _value), _row, _col)
1555
1559
  end
@@ -1634,7 +1638,7 @@ module Writexlsx
1634
1638
  #
1635
1639
  def write_dynamic_array_formula(row1, col1, row2 = nil, col2 = nil, formula = nil, format = nil, value = nil)
1636
1640
  write_array_formula_base('d', row1, col1, row2, col2, formula, format, value)
1637
- @has_dynamic_arrays = true
1641
+ @has_dynamic_functions = true
1638
1642
  end
1639
1643
 
1640
1644
  #
@@ -1782,21 +1786,23 @@ module Writexlsx
1782
1786
  # The label is written using the {#write()}[#method-i-write] method. Therefore it is
1783
1787
  # possible to write strings, numbers or formulas as labels.
1784
1788
  #
1785
- def write_url(row, col, url = nil, format = nil, str = nil, tip = nil)
1789
+ def write_url(row, col, url = nil, format = nil, str = nil, tip = nil, ignore_write_string = false)
1786
1790
  # Check for a cell reference in A1 notation and substitute row and column
1787
1791
  if (row_col_array = row_col_notation(row))
1788
- _row, _col = row_col_array
1789
- _url = col
1790
- _format = url
1791
- _str = format
1792
- _tip = str
1792
+ _row, _col = row_col_array
1793
+ _url = col
1794
+ _format = url
1795
+ _str = format
1796
+ _tip = str
1797
+ _ignore_write_string = tip
1793
1798
  else
1794
- _row = row
1795
- _col = col
1796
- _url = url
1797
- _format = format
1798
- _str = str
1799
- _tip = tip
1799
+ _row = row
1800
+ _col = col
1801
+ _url = url
1802
+ _format = format
1803
+ _str = str
1804
+ _tip = tip
1805
+ _ignore_write_string = ignore_write_string
1800
1806
  end
1801
1807
  _format, _str = _str, _format if _str.respond_to?(:xf_index) || !_format.respond_to?(:xf_index)
1802
1808
  raise WriteXLSXInsufficientArgumentError if [_row, _col, _url].include?(nil)
@@ -1814,7 +1820,7 @@ module Writexlsx
1814
1820
  _format ||= @default_url_format
1815
1821
 
1816
1822
  # Write the hyperlink string.
1817
- write_string(_row, _col, hyperlink.str, _format)
1823
+ write_string(_row, _col, hyperlink.str, _format) unless _ignore_write_string
1818
1824
  end
1819
1825
 
1820
1826
  #
@@ -1959,6 +1965,65 @@ module Writexlsx
1959
1965
  ]
1960
1966
  end
1961
1967
 
1968
+ #
1969
+ # Embed an image into the worksheet.
1970
+ #
1971
+ def embed_image(row, col, filename, options = nil)
1972
+ # Check for a cell reference in A1 notation and substitute row and column.
1973
+ if (row_col_array = row_col_notation(row))
1974
+ _row, _col = row_col_array
1975
+ image = col
1976
+ _options = filename
1977
+ else
1978
+ _row = row
1979
+ _col = col
1980
+ image = filename
1981
+ _options = options
1982
+ end
1983
+ xf, url, tip, description, decorative = []
1984
+
1985
+ raise WriteXLSXInsufficientArgumentError if [_row, _col, image].include?(nil)
1986
+ raise "Couldn't locate #{image}" unless File.exist?(image)
1987
+
1988
+ # Check that row and col are valid and store max and min values
1989
+ check_dimensions(_row, _col)
1990
+ store_row_col_max_min_values(_row, _col)
1991
+
1992
+ if options
1993
+ xf = options[:cell_format]
1994
+ url = options[:url]
1995
+ tip = options[:tip]
1996
+ description = options[:description]
1997
+ decorative = options[:decorative]
1998
+ end
1999
+
2000
+ # Write the url without writing a string.
2001
+ if url
2002
+ xf ||= @default_url_format
2003
+
2004
+ write_url(row, col, url, xf, nil, tip, true)
2005
+ end
2006
+
2007
+ # Get the image properties, mainly for the type and checksum.
2008
+ image_properties = get_image_properties(image)
2009
+ type = image_properties[0]
2010
+ md5 = image_properties[6]
2011
+
2012
+ # Check for duplicate images.
2013
+ image_index = @embedded_image_indexes[md5]
2014
+
2015
+ unless ptrue?(image_index)
2016
+ @workbook.embedded_images << [image, type, description, decorative]
2017
+
2018
+ image_index = @workbook.embedded_images.size
2019
+ @embedded_image_indexes[md5] = image_index
2020
+ end
2021
+
2022
+ # Write the cell placeholder.
2023
+ store_data_to_table(EmbedImageCellData.new(image_index, xf), _row, _col)
2024
+ @has_embedded_images = true
2025
+ end
2026
+
1962
2027
  #
1963
2028
  # :call-seq:
1964
2029
  # repeat_formula(row, column, formula [ , format ])
@@ -2799,8 +2864,12 @@ module Writexlsx
2799
2864
  end
2800
2865
  end
2801
2866
 
2802
- def has_dynamic_arrays?
2803
- @has_dynamic_arrays
2867
+ def has_dynamic_functions?
2868
+ @has_dynamic_functions
2869
+ end
2870
+
2871
+ def has_embedded_images?
2872
+ @has_embedded_images
2804
2873
  end
2805
2874
 
2806
2875
  private
@@ -3278,6 +3347,7 @@ EOS
3278
3347
  end
3279
3348
 
3280
3349
  @drawing_links << ['/image', "../media/image#{image_id}.#{image_type}"] unless @drawing_rels[md5]
3350
+
3281
3351
  drawing.rel_index = drawing_rel_index(md5)
3282
3352
  end
3283
3353
  public :prepare_image
@@ -4256,9 +4326,10 @@ EOS
4256
4326
 
4257
4327
  # If the cell isn't a string then we have to add the url as
4258
4328
  # the string to display
4259
- if ptrue?(@cell_data_table) &&
4260
- ptrue?(@cell_data_table[row_num]) &&
4261
- ptrue?(@cell_data_table[row_num][col_num]) && @cell_data_table[row_num][col_num].display_url_string?
4329
+ if ptrue?(@cell_data_table) &&
4330
+ ptrue?(@cell_data_table[row_num]) &&
4331
+ ptrue?(@cell_data_table[row_num][col_num]) &&
4332
+ @cell_data_table[row_num][col_num].display_url_string?
4262
4333
  link.display_on
4263
4334
  end
4264
4335
 
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: 1.11.2
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hideo NAKAMURA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-26 00:00:00.000000000 Z
11
+ date: 2024-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nkf
@@ -266,6 +266,10 @@ files:
266
266
  - lib/write_xlsx/package/metadata.rb
267
267
  - lib/write_xlsx/package/packager.rb
268
268
  - lib/write_xlsx/package/relationships.rb
269
+ - lib/write_xlsx/package/rich_value.rb
270
+ - lib/write_xlsx/package/rich_value_rel.rb
271
+ - lib/write_xlsx/package/rich_value_structure.rb
272
+ - lib/write_xlsx/package/rich_value_types.rb
269
273
  - lib/write_xlsx/package/shared_strings.rb
270
274
  - lib/write_xlsx/package/styles.rb
271
275
  - lib/write_xlsx/package/table.rb
@@ -304,7 +308,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
304
308
  - !ruby/object:Gem::Version
305
309
  version: '0'
306
310
  requirements: []
307
- rubygems_version: 3.5.3
311
+ rubygems_version: 3.4.19
308
312
  signing_key:
309
313
  specification_version: 4
310
314
  summary: write_xlsx is a gem to create a new file in the Excel 2007+ XLSX format.