write_xlsx 0.65.1 → 0.69.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +7 -0
  3. data/lib/write_xlsx/chart.rb +20 -2
  4. data/lib/write_xlsx/drawing.rb +4 -7
  5. data/lib/write_xlsx/package/comments.rb +13 -10
  6. data/lib/write_xlsx/package/conditional_format.rb +1 -1
  7. data/lib/write_xlsx/package/table.rb +4 -18
  8. data/lib/write_xlsx/package/vml.rb +2 -2
  9. data/lib/write_xlsx/sheets.rb +10 -4
  10. data/lib/write_xlsx/utility.rb +7 -10
  11. data/lib/write_xlsx/version.rb +1 -1
  12. data/lib/write_xlsx/workbook.rb +73 -88
  13. data/lib/write_xlsx/worksheet.rb +39 -85
  14. data/lib/write_xlsx/worksheet/hyperlink.rb +2 -1
  15. data/test/drawing/test_write_c_chart.rb +1 -1
  16. data/test/package/table/test_table13.rb +69 -0
  17. data/test/regression/test_button08.rb +28 -0
  18. data/test/regression/test_chart_axis25.rb +45 -0
  19. data/test/regression/test_chart_axis26.rb +45 -0
  20. data/test/regression/test_chart_axis27.rb +45 -0
  21. data/test/regression/test_chart_axis28.rb +45 -0
  22. data/test/regression/test_chart_axis29.rb +44 -0
  23. data/test/regression/test_chart_scatter08.rb +57 -0
  24. data/test/regression/test_comment11.rb +33 -0
  25. data/test/regression/test_selection01.rb +23 -0
  26. data/test/regression/test_selection02.rb +33 -0
  27. data/test/regression/test_shape01.rb +25 -0
  28. data/test/regression/test_shape02.rb +42 -0
  29. data/test/regression/test_shape03.rb +45 -0
  30. data/test/regression/test_shape04.rb +43 -0
  31. data/test/regression/test_table15.rb +37 -0
  32. data/test/regression/test_utf8_01.rb +23 -0
  33. data/test/regression/test_utf8_03.rb +23 -0
  34. data/test/regression/test_utf8_04.rb +23 -0
  35. data/test/regression/test_utf8_05.rb +26 -0
  36. data/test/regression/test_utf8_06.rb +28 -0
  37. data/test/regression/test_utf8_07.rb +27 -0
  38. data/test/regression/test_utf8_08.rb +38 -0
  39. data/test/regression/test_utf8_09.rb +24 -0
  40. data/test/regression/test_utf8_10.rb +42 -0
  41. data/test/regression/xlsx_files/button08.xlsx +0 -0
  42. data/test/regression/xlsx_files/button09.xlsx +0 -0
  43. data/test/regression/xlsx_files/button10.xlsx +0 -0
  44. data/test/regression/xlsx_files/button11.xlsx +0 -0
  45. data/test/regression/xlsx_files/button12.xlsx +0 -0
  46. data/test/regression/xlsx_files/chart_axis25.xlsx +0 -0
  47. data/test/regression/xlsx_files/chart_axis26.xlsx +0 -0
  48. data/test/regression/xlsx_files/chart_axis27.xlsx +0 -0
  49. data/test/regression/xlsx_files/chart_axis28.xlsx +0 -0
  50. data/test/regression/xlsx_files/chart_axis29.xlsx +0 -0
  51. data/test/regression/xlsx_files/chart_scatter08.xlsx +0 -0
  52. data/test/regression/xlsx_files/comment11.xlsx +0 -0
  53. data/test/regression/xlsx_files/selection01.xlsx +0 -0
  54. data/test/regression/xlsx_files/selection02.xlsx +0 -0
  55. data/test/regression/xlsx_files/shape01.xlsx +0 -0
  56. data/test/regression/xlsx_files/shape02.xlsx +0 -0
  57. data/test/regression/xlsx_files/shape03.xlsx +0 -0
  58. data/test/regression/xlsx_files/shape04.xlsx +0 -0
  59. data/test/regression/xlsx_files/table15.xlsx +0 -0
  60. data/test/regression/xlsx_files/utf8_01.xlsx +0 -0
  61. data/test/regression/xlsx_files/utf8_03.xlsx +0 -0
  62. data/test/regression/xlsx_files/utf8_04.xlsx +0 -0
  63. data/test/regression/xlsx_files/utf8_05.xlsx +0 -0
  64. data/test/regression/xlsx_files/utf8_06.xlsx +0 -0
  65. data/test/regression/xlsx_files/utf8_07.xlsx +0 -0
  66. data/test/regression/xlsx_files/utf8_08.xlsx +0 -0
  67. data/test/regression/xlsx_files/utf8_09.xlsx +0 -0
  68. data/test/regression/xlsx_files/utf8_10.xlsx +0 -0
  69. data/test/workbook/test_define_name.rb +16 -0
  70. data/test/worksheet/test_cond_format_18.rb +1 -1
  71. data/test/worksheet/test_convert_date_time_04.rb +19 -0
  72. data/test/worksheet/test_write_row_element.rb +14 -14
  73. metadata +113 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2625f80bf9b7f0ba2835f94cd5dd5699a86d1cba
4
- data.tar.gz: a33f1666db5bd2bad62b7f0e97bb9422f03337fd
3
+ metadata.gz: 0b64b508ff280aa34008fca70ef3554cfd2aae0f
4
+ data.tar.gz: e9ca4ef7d80c4bf39be76c842725fd08f71d22fa
5
5
  SHA512:
6
- metadata.gz: f8fb864b91fffd56d02dab919dea687a9a66dd22ed2c2b2a5240e72e830ae835781aa59a873ceb76391d1b8a4624fee72c4be9a5cbf7c4eb95773fd756b11e98
7
- data.tar.gz: 2913180a8541b9c17293e2d3bc1e4bae00d8b3964726b6c2a30cb7c51b7b52963b8f64d11f7ce4318a70438d740b7932b30944813c368a89947c3ef3c66a38e9
6
+ metadata.gz: 2b857dd675e58f9f2bc4e064ad133d4237c87d27809852688bd2e2f58ea70fb520b239a1924b92a4856c866fbcdb73ece933808f1aa5380d6a31c3b91e3fd8ff
7
+ data.tar.gz: 6ea66fc1fe51560bde230f42a5d6b119b59285a321f86f7c7d9776fcd83b24f4b21afcedd8be954df17a173d113a0dd765b830e704309219a365454be34ad5b2
data/README.rdoc CHANGED
@@ -75,6 +75,13 @@ the first worksheet in an Excel XML spreadsheet called ruby.xlsx:
75
75
  workbook.close
76
76
 
77
77
  == Recent change
78
+ 2013-06-30 v0.69.0
79
+ Added chart font rotation property. Mainly for use with data axes to make the display more compact.
80
+ Fix for issue where shapes on one worksheet corrupted charts on a subsequent worksheet.
81
+ Fix for issue where add_button invalidated cell comments in the same workbook.
82
+ Fix for set_selection with cell range.
83
+ Fix for issue with image scaling.
84
+
78
85
  2013-03-23 v0.65.1
79
86
  Bug fix for non-integer image scaling.
80
87
  Bug fix in Worksheet#set_first_sheet
@@ -1790,12 +1790,18 @@ def convert_font_args(params)
1790
1790
  :_underline => params[:underline],
1791
1791
  :_pitch_family => params[:pitch_family],
1792
1792
  :_charset => params[:charset],
1793
- :_baseline => params[:baseline] || 0
1793
+ :_baseline => params[:baseline] || 0,
1794
+ :_rotation => params[:rotation]
1794
1795
  }
1795
1796
 
1796
1797
  # Convert font size units.
1797
1798
  font[:_size] *= 100 if font[:_size] && font[:_size] != 0
1798
1799
 
1800
+ # Convert rotation into 60,000ths of a degree.
1801
+ if ptrue?(font[:_rotation])
1802
+ font[:_rotation] = 60_000 * font[:_rotation].to_i
1803
+ end
1804
+
1799
1805
  font
1800
1806
  end
1801
1807
 
@@ -3427,6 +3433,18 @@ def write_a_body_pr(horiz) # :nodoc:
3427
3433
  @writer.empty_tag('a:bodyPr', attributes)
3428
3434
  end
3429
3435
 
3436
+ #
3437
+ # Write the <a:bodyPr> element for axis fonts.
3438
+ #
3439
+ def write_axis_body_pr(rot = nil, vert = nil)
3440
+ attributes = []
3441
+
3442
+ attributes << 'rot' << rot if rot
3443
+ attributes << 'vert' << vert if vert
3444
+
3445
+ @writer.empty_tag('a:bodyPr', attributes)
3446
+ end
3447
+
3430
3448
  #
3431
3449
  # Write the <a:lstStyle> element.
3432
3450
  #
@@ -3989,7 +4007,7 @@ def write_axis_font(font) # :nodoc:
3989
4007
  return unless font
3990
4008
 
3991
4009
  @writer.tag_elements('c:txPr') do
3992
- @writer.empty_tag('a:bodyPr')
4010
+ write_axis_body_pr(font[:_rotation])
3993
4011
  write_a_lst_style
3994
4012
  @writer.tag_elements('a:p') do
3995
4013
  write_a_p_pr_rich(font)
@@ -367,24 +367,21 @@ def write_atag_graphic_data(index)
367
367
 
368
368
  @writer.tag_elements('a:graphicData', attributes) do
369
369
  # Write the c:chart element.
370
- write_c_chart("rId#{index}")
370
+ write_c_chart(index)
371
371
  end
372
372
  end
373
373
 
374
374
  #
375
375
  # Write the <c:chart> element.
376
376
  #
377
- def write_c_chart(r_id)
377
+ def write_c_chart(id)
378
378
  schema = 'http://schemas.openxmlformats.org/'
379
379
  xmlns_c = "#{schema}drawingml/2006/chart"
380
380
  xmlns_r = "#{schema}officeDocument/2006/relationships"
381
381
 
382
382
 
383
- attributes = [
384
- 'xmlns:c', xmlns_c,
385
- 'xmlns:r', xmlns_r,
386
- 'r:id', r_id
387
- ]
383
+ attributes = ['xmlns:c', xmlns_c, 'xmlns:r', xmlns_r]
384
+ attributes += r_id_attributes(id)
388
385
 
389
386
  @writer.empty_tag('c:chart', attributes)
390
387
  end
@@ -263,18 +263,21 @@ def assemble_xml_file
263
263
  end
264
264
 
265
265
  def sorted_comments
266
- @sorted_comments = []
267
- # We sort the comments by row and column but that isn't strictly required.
268
- @comments.keys.sort.each do |row|
269
- @comments[row].keys.sort.each do |col|
270
- # Set comment visibility if required and not already user defined.
271
- @comments[row][col].visible ||= 1 if comments_visible?
272
-
273
- # Set comment author if not already user defined.
274
- @comments[row][col].author ||= @worksheet.comments_author
275
- @sorted_comments << @comments[row][col]
266
+ unless @sorted_comments
267
+ @sorted_comments = []
268
+ # We sort the comments by row and column but that isn't strictly required.
269
+ @comments.keys.sort.each do |row|
270
+ @comments[row].keys.sort.each do |col|
271
+ # Set comment visibility if required and not already user defined.
272
+ @comments[row][col].visible ||= 1 if comments_visible?
273
+
274
+ # Set comment author if not already user defined.
275
+ @comments[row][col].author ||= @worksheet.comments_author
276
+ @sorted_comments << @comments[row][col]
277
+ end
276
278
  end
277
279
  end
280
+
278
281
  @sorted_comments
279
282
  end
280
283
 
@@ -304,7 +304,7 @@ def row_col_param_for_conditional_formatting(*args)
304
304
  # Check for a cell reference in A1 notation and substitute row and column
305
305
  if args[0] =~ /^\D/
306
306
  # Check for a user defined multiple range like B3:K6,B8:K11.
307
- user_range = args[0].gsub(/\s*,\s*/, ' ').gsub(/\$/, '') if args[0] =~ /,/
307
+ user_range = args[0].sub(/^=/, '').gsub(/\s*,\s*/, ' ').gsub(/\$/, '') if args[0] =~ /,/
308
308
  end
309
309
 
310
310
  row1, col1, row2, col2, param = row_col_notation(args)
@@ -24,8 +24,6 @@ def initialize(id, param = {})
24
24
  end
25
25
  end
26
26
 
27
- # attr_reader :id
28
-
29
27
  def initialize(worksheet, id, *args)
30
28
  @worksheet = worksheet
31
29
  @writer = Package::XMLWriterSimple.new
@@ -204,25 +202,15 @@ def valid_table_parameter
204
202
  def handle_the_column_formula(col_data, col_num, formula, format)
205
203
  return unless formula
206
204
 
207
- # Remove the leading = from formula.
208
- formula.sub!(/^=/, '')
209
- # Covert Excel 2010 "@" ref to 2007 "#This Row".
210
- formula.gsub!(/@/,'[#This Row],')
211
-
212
- col_data.formula = formula
205
+ col_data.formula = formula.sub(/^=/, '').gsub(/@/,'[#This Row],')
213
206
 
214
207
  (@first_data_row..@last_data_row).each do |row|
215
- @worksheet.write_formula(row, col_num, formula, format)
208
+ @worksheet.write_formula(row, col_num, col_data.formula, format)
216
209
  end
217
210
  end
218
211
 
219
212
  def handle_the_function_for_the_table_row(row2, col_data, col_num, total_function, format)
220
- function = total_function
221
-
222
- # Massage the function name.
223
- function = function.downcase
224
- function.gsub!(/_/, '')
225
- function.gsub!(/\s/,'')
213
+ function = total_function.downcase.gsub(/[_\s]/, '')
226
214
 
227
215
  function = 'countNums' if function == 'countnums'
228
216
  function = 'stdDev' if function == 'stddev'
@@ -272,9 +260,7 @@ def set_the_table_options
272
260
 
273
261
  def set_the_table_style
274
262
  if @param[:style]
275
- @style = @param[:style]
276
- # Remove whitespace from style name.
277
- @style.gsub!(/\s/, '')
263
+ @style = @param[:style].gsub(/\s/, '')
278
264
  else
279
265
  @style = "TableStyleMedium9"
280
266
  end
@@ -33,9 +33,9 @@ def assemble_xml_file(worksheet)
33
33
  write_button_shapetype
34
34
  end
35
35
  end
36
- unless worksheet.comments_array.empty?
36
+ unless worksheet.sorted_comments.empty?
37
37
  write_shape_type_and_shape(
38
- worksheet.comments_array,
38
+ worksheet.sorted_comments,
39
39
  vml_shape_id, z_index) do
40
40
  write_comment_shapetype
41
41
  end
@@ -100,8 +100,14 @@ def write_drawing_rels_files(package_dir)
100
100
 
101
101
  # )
102
102
  dir = "#{package_dir}/xl/drawings/_rels"
103
- self.reject { |sheet| sheet.drawing_links[0].empty? }.
104
- each_with_index do |sheet, index|
103
+
104
+ index = 0
105
+ self.each do |sheet|
106
+ if !sheet.drawing_links[0].empty? || sheet.has_shapes?
107
+ index += 1
108
+ end
109
+
110
+ next if sheet.drawing_links[0].empty?
105
111
 
106
112
  FileUtils.mkdir_p(dir)
107
113
 
@@ -114,7 +120,7 @@ def write_drawing_rels_files(package_dir)
114
120
  end
115
121
 
116
122
  # Create the .rels file such as /xl/drawings/_rels/sheet1.xml.rels.
117
- rels.set_xml_writer("#{dir}/drawing#{index+1}.xml.rels")
123
+ rels.set_xml_writer("#{dir}/drawing#{index}.xml.rels")
118
124
  rels.assemble_xml_file
119
125
  end
120
126
  end
@@ -216,7 +222,7 @@ def write_sheet(writer, sheet, sheet_id) #:nodoc:
216
222
  if sheet.hidden?
217
223
  attributes << 'state' << 'hidden'
218
224
  end
219
- attributes << 'r:id' << "rId#{sheet_id}"
225
+ attributes += r_id_attributes(sheet_id)
220
226
  writer.empty_tag_encoded('sheet', attributes)
221
227
  end
222
228
  end
@@ -119,14 +119,7 @@ def check_dimensions(row, col)
119
119
  # nil if the date is invalid.
120
120
  #
121
121
  def convert_date_time(date_time_string) #:nodoc:
122
- date_time = date_time_string
123
-
124
- days = 0 # Number of days since epoch
125
- seconds = 0 # Time expressed as fraction of 24h hours in seconds
126
-
127
- # Strip leading and trailing whitespace.
128
- date_time.sub!(/^\s+/, '')
129
- date_time.sub!(/\s+$/, '')
122
+ date_time = date_time_string.sub(/^\s+/, '').sub(/\s+$/, '').sub(/Z$/, '')
130
123
 
131
124
  # Check for invalid date char.
132
125
  return nil if date_time =~ /[^0-9T:\-\.Z]/
@@ -134,8 +127,8 @@ def convert_date_time(date_time_string) #:nodoc:
134
127
  # Check for "T" after date or before time.
135
128
  return nil unless date_time =~ /\dT|T\d/
136
129
 
137
- # Strip trailing Z in ISO8601 date.
138
- date_time.sub!(/Z$/, '')
130
+ days = 0 # Number of days since epoch
131
+ seconds = 0 # Time expressed as fraction of 24h hours in seconds
139
132
 
140
133
  # Split into date and time.
141
134
  date, time = date_time.split(/T/)
@@ -495,5 +488,9 @@ def write_stroke
495
488
 
496
489
  @writer.empty_tag('v:stroke', attributes)
497
490
  end
491
+
492
+ def r_id_attributes(id)
493
+ ['r:id', "rId#{id}"]
494
+ end
498
495
  end
499
496
  end
@@ -1,5 +1,5 @@
1
1
  require 'write_xlsx/workbook'
2
2
 
3
3
  class WriteXLSX < Writexlsx::Workbook
4
- VERSION = "0.65.1"
4
+ VERSION = "0.69.0"
5
5
  end
@@ -41,7 +41,7 @@ class Workbook
41
41
  attr_writer :firstsheet # :nodoc:
42
42
  attr_reader :palette # :nodoc:
43
43
  attr_reader :worksheets, :charts, :drawings # :nodoc:
44
- attr_reader :num_comment_files, :num_vml_files, :named_ranges # :nodoc:
44
+ attr_reader :named_ranges # :nodoc:
45
45
  attr_reader :doc_properties # :nodoc:
46
46
  attr_reader :image_types, :images # :nodoc:
47
47
  attr_reader :shared_strings # :nodoc:
@@ -111,8 +111,6 @@ def initialize(file, default_formats = {})
111
111
  @custom_colors = []
112
112
  @doc_properties = {}
113
113
  @local_time = Time.now
114
- @num_vml_files = 0
115
- @num_comment_files = 0
116
114
  @optimization = 0
117
115
  @x_window = 240
118
116
  @y_window = 15
@@ -247,31 +245,29 @@ def assemble_xml_file #:nodoc:
247
245
  write_xml_declaration
248
246
 
249
247
  # Write the root workbook element.
250
- write_workbook
248
+ write_workbook do
251
249
 
252
- # Write the XLSX file version.
253
- write_file_version
250
+ # Write the XLSX file version.
251
+ write_file_version
254
252
 
255
- # Write the workbook properties.
256
- write_workbook_pr
253
+ # Write the workbook properties.
254
+ write_workbook_pr
257
255
 
258
- # Write the workbook view properties.
259
- write_book_views
256
+ # Write the workbook view properties.
257
+ write_book_views
260
258
 
261
- # Write the worksheet names and ids.
262
- @worksheets.write_sheets(@writer)
259
+ # Write the worksheet names and ids.
260
+ @worksheets.write_sheets(@writer)
263
261
 
264
- # Write the workbook defined names.
265
- write_defined_names
262
+ # Write the workbook defined names.
263
+ write_defined_names
266
264
 
267
- # Write the workbook calculation properties.
268
- write_calc_pr
265
+ # Write the workbook calculation properties.
266
+ write_calc_pr
269
267
 
270
- # Write the workbook extension storage.
271
- #write_ext_lst
272
-
273
- # Close the workbook tag.
274
- write_workbook_end
268
+ # Write the workbook extension storage.
269
+ #write_ext_lst
270
+ end
275
271
 
276
272
  # Close the XML writer object and filehandle.
277
273
  @writer.crlf
@@ -655,7 +651,7 @@ def add_format(properties = {})
655
651
  # This is not very useful for inserting multiple shapes,
656
652
  # since the x/y coordinates also gets modified.
657
653
  #
658
- def add_shape(properties)
654
+ def add_shape(properties = {})
659
655
  shape = Shape.new(properties)
660
656
  shape.palette = @palette
661
657
 
@@ -693,10 +689,6 @@ def add_shape(properties)
693
689
  def define_name(name, formula)
694
690
  sheet_index = nil
695
691
  sheetname = ''
696
- full_name = name
697
-
698
- # Remove the = sign from the formula if it exists.
699
- formula.sub!(/^=/, '')
700
692
 
701
693
  # Local defined names are formatted like "Sheet1!name".
702
694
  if name =~ /^(.*)!(.*)$/
@@ -722,7 +714,7 @@ def define_name(name, formula)
722
714
  raise "Invalid name '#{name}' looks like a cell name in defined_name()\n"
723
715
  end
724
716
 
725
- @defined_names.push([ name, sheet_index, formula])
717
+ @defined_names.push([ name, sheet_index, formula.sub(/^=/, '') ])
726
718
  end
727
719
 
728
720
  #
@@ -949,6 +941,14 @@ def style_properties
949
941
  ]
950
942
  end
951
943
 
944
+ def num_vml_files
945
+ @worksheets.select { |sheet| sheet.has_vml? }.count
946
+ end
947
+
948
+ def num_comment_files
949
+ @worksheets.select { |sheet| sheet.has_comments? }.count
950
+ end
951
+
952
952
  private
953
953
 
954
954
  def setup_filename(file) #:nodoc:
@@ -1085,11 +1085,9 @@ def write_workbook #:nodoc:
1085
1085
  'xmlns:r',
1086
1086
  schema + '/officeDocument/2006/relationships'
1087
1087
  ]
1088
- @writer.start_tag('workbook', attributes)
1089
- end
1090
-
1091
- def write_workbook_end #:nodoc:
1092
- @writer.end_tag('workbook')
1088
+ @writer.tag_elements('workbook', attributes) do
1089
+ yield
1090
+ end
1093
1091
  end
1094
1092
 
1095
1093
  def write_file_version #:nodoc:
@@ -1144,18 +1142,15 @@ def write_calc_pr #:nodoc:
1144
1142
  end
1145
1143
 
1146
1144
  def write_ext_lst #:nodoc:
1147
- tag = 'extLst'
1148
- @writer.tag_elements(tag) { write_ext }
1145
+ @writer.tag_elements('extLst') { write_ext }
1149
1146
  end
1150
1147
 
1151
1148
  def write_ext #:nodoc:
1152
- tag = 'ext'
1153
- uri = "#{OFFICE_URL}mac/excel/2008/main"
1154
1149
  attributes = [
1155
- 'xmlns:mx', uri,
1150
+ 'xmlns:mx', "#{OFFICE_URL}mac/excel/2008/main",
1156
1151
  'uri', uri
1157
1152
  ]
1158
- @writer.tag_elements(tag, attributes) { write_mx_arch_id }
1153
+ @writer.tag_elements('ext', attributes) { write_mx_arch_id }
1159
1154
  end
1160
1155
 
1161
1156
  def write_mx_arch_id #:nodoc:
@@ -1164,14 +1159,13 @@ def write_mx_arch_id #:nodoc:
1164
1159
 
1165
1160
  def write_defined_names #:nodoc:
1166
1161
  return if @defined_names.nil? || @defined_names.empty?
1167
- tag = 'definedNames'
1168
- @writer.tag_elements(tag) do
1162
+ @writer.tag_elements('definedNames') do
1169
1163
  @defined_names.each { |defined_name| write_defined_name(defined_name) }
1170
1164
  end
1171
1165
  end
1172
1166
 
1173
- def write_defined_name(data) #:nodoc:
1174
- name, id, range, hidden = data
1167
+ def write_defined_name(defined_name) #:nodoc:
1168
+ name, id, range, hidden = defined_name
1175
1169
 
1176
1170
  attributes = ['name', name]
1177
1171
  attributes << 'localSheetId' << "#{id}" unless id == -1
@@ -1424,30 +1418,28 @@ def ne_0?(val)
1424
1418
  # the named ranges for App.xml.
1425
1419
  #
1426
1420
  def prepare_defined_names #:nodoc:
1427
- defined_names = @defined_names
1428
-
1429
1421
  @worksheets.each do |sheet|
1430
1422
  # Check for Print Area settings.
1431
1423
  if sheet.autofilter_area
1432
- range = sheet.autofilter_area
1433
- hidden = 1
1434
-
1435
- # Store the defined names.
1436
- defined_names << ['_xlnm._FilterDatabase', sheet.index, range, hidden]
1424
+ @defined_names << [
1425
+ '_xlnm._FilterDatabase',
1426
+ sheet.index,
1427
+ sheet.autofilter_area,
1428
+ 1
1429
+ ]
1437
1430
  end
1438
1431
 
1439
1432
  # Check for Print Area settings.
1440
1433
  if !sheet.print_area.empty?
1441
- range = sheet.print_area
1442
-
1443
- # Store the defined names.
1444
- defined_names << ['_xlnm.Print_Area', sheet.index, range]
1434
+ @defined_names << [
1435
+ '_xlnm.Print_Area',
1436
+ sheet.index,
1437
+ sheet.print_area
1438
+ ]
1445
1439
  end
1446
1440
 
1447
1441
  # Check for repeat rows/cols. aka, Print Titles.
1448
1442
  if !sheet.print_repeat_cols.empty? || !sheet.print_repeat_rows.empty?
1449
- range = ''
1450
-
1451
1443
  if !sheet.print_repeat_cols.empty? && !sheet.print_repeat_rows.empty?
1452
1444
  range = sheet.print_repeat_cols + ',' + sheet.print_repeat_rows
1453
1445
  else
@@ -1455,55 +1447,49 @@ def prepare_defined_names #:nodoc:
1455
1447
  end
1456
1448
 
1457
1449
  # Store the defined names.
1458
- defined_names << ['_xlnm.Print_Titles', sheet.index, range]
1450
+ @defined_names << ['_xlnm.Print_Titles', sheet.index, range]
1459
1451
  end
1460
1452
  end
1461
1453
 
1462
- defined_names = sort_defined_names(defined_names)
1463
- @defined_names = defined_names
1464
- @named_ranges = extract_named_ranges(defined_names)
1454
+ @defined_names = sort_defined_names(@defined_names)
1455
+ @named_ranges = extract_named_ranges(@defined_names)
1465
1456
  end
1466
1457
 
1467
1458
  #
1468
1459
  # Iterate through the worksheets and set up the VML objects.
1469
1460
  #
1470
1461
  def prepare_vml_objects #:nodoc:
1471
- comment_id = 0
1472
- vml_data_id = 1
1473
- vml_shape_id = 1024
1474
- vml_files = 0
1475
- comment_files = 0
1462
+ comment_id = 0
1463
+ vml_drawing_id = 0
1464
+ vml_data_id = 1
1465
+ vml_shape_id = 1024
1476
1466
 
1477
- @worksheets.each do |sheet|
1478
- next unless sheet.has_vml?
1479
- vml_files += 1
1480
- comment_files += 1 if sheet.has_comments?
1467
+ @worksheets.select { |sheet| sheet.has_vml? }.each do |sheet|
1468
+ comment_id += 1 if sheet.has_comments?
1469
+ vml_drawing_id += 1
1481
1470
 
1482
- comment_id += 1
1483
- count = sheet.prepare_vml_objects(vml_data_id, vml_shape_id, comment_id)
1471
+ sheet.prepare_vml_objects(vml_data_id, vml_shape_id,
1472
+ vml_drawing_id, comment_id)
1484
1473
 
1485
1474
  # Each VML file should start with a shape id incremented by 1024.
1486
- vml_data_id += 1 * ( ( 1024 + sheet.comments_count ) / 1024.0 ).to_i
1487
- vml_shape_id += 1024 * ( ( 1024 + sheet.comments_count ) / 1024.0 ).to_i
1475
+ vml_data_id += 1 * ( 1 + sheet.num_comments_block )
1476
+ vml_shape_id += 1024 * ( 1 + sheet.num_comments_block )
1488
1477
  end
1489
1478
 
1490
- @num_vml_files = vml_files
1491
- @num_comment_files = comment_files
1492
-
1493
- # Add a font format for cell comments.
1494
- if comment_files > 0
1495
- format = Format.new(
1496
- @formats,
1497
- :font => 'Tahoma',
1498
- :size => 8,
1499
- :color_indexed => 81,
1500
- :font_only => 1
1501
- )
1479
+ add_font_format_for_cell_comments if num_comment_files > 0
1480
+ end
1502
1481
 
1503
- format.get_xf_index
1482
+ def add_font_format_for_cell_comments
1483
+ format = Format.new(
1484
+ @formats,
1485
+ :font => 'Tahoma',
1486
+ :size => 8,
1487
+ :color_indexed => 81,
1488
+ :font_only => 1
1489
+ )
1504
1490
 
1505
- @formats.formats << format
1506
- end
1491
+ format.get_xf_index
1492
+ @formats.formats << format
1507
1493
  end
1508
1494
 
1509
1495
  #
@@ -1569,7 +1555,6 @@ def chart_data(worksheet, cells)
1569
1555
  end
1570
1556
  end
1571
1557
  end
1572
- private :chart_data
1573
1558
 
1574
1559
  #
1575
1560
  # Sort internal and user defined names in the same order as used by Excel.