caxlsx 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +24 -5
  4. data/Rakefile +0 -1
  5. data/lib/axlsx/content_type/abstract_content_type.rb +2 -5
  6. data/lib/axlsx/content_type/content_type.rb +0 -4
  7. data/lib/axlsx/content_type/default.rb +1 -5
  8. data/lib/axlsx/content_type/override.rb +0 -4
  9. data/lib/axlsx/doc_props/app.rb +1 -6
  10. data/lib/axlsx/doc_props/core.rb +1 -6
  11. data/lib/axlsx/drawing/area_chart.rb +3 -6
  12. data/lib/axlsx/drawing/area_series.rb +1 -4
  13. data/lib/axlsx/drawing/ax_data_source.rb +1 -6
  14. data/lib/axlsx/drawing/axes.rb +5 -6
  15. data/lib/axlsx/drawing/axis.rb +7 -12
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +7 -10
  17. data/lib/axlsx/drawing/bar_chart.rb +6 -9
  18. data/lib/axlsx/drawing/bar_series.rb +2 -8
  19. data/lib/axlsx/drawing/bubble_chart.rb +2 -5
  20. data/lib/axlsx/drawing/bubble_series.rb +3 -6
  21. data/lib/axlsx/drawing/cat_axis.rb +2 -7
  22. data/lib/axlsx/drawing/chart.rb +7 -12
  23. data/lib/axlsx/drawing/d_lbls.rb +23 -22
  24. data/lib/axlsx/drawing/drawing.rb +4 -8
  25. data/lib/axlsx/drawing/graphic_frame.rb +0 -3
  26. data/lib/axlsx/drawing/hyperlink.rb +4 -7
  27. data/lib/axlsx/drawing/line_3D_chart.rb +10 -14
  28. data/lib/axlsx/drawing/line_chart.rb +3 -6
  29. data/lib/axlsx/drawing/line_series.rb +1 -4
  30. data/lib/axlsx/drawing/marker.rb +5 -9
  31. data/lib/axlsx/drawing/num_data.rb +4 -9
  32. data/lib/axlsx/drawing/num_data_source.rb +3 -7
  33. data/lib/axlsx/drawing/num_val.rb +2 -5
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +4 -6
  35. data/lib/axlsx/drawing/pic.rb +46 -13
  36. data/lib/axlsx/drawing/picture_locking.rb +3 -6
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -7
  38. data/lib/axlsx/drawing/pie_series.rb +1 -6
  39. data/lib/axlsx/drawing/scaling.rb +2 -5
  40. data/lib/axlsx/drawing/scatter_chart.rb +2 -5
  41. data/lib/axlsx/drawing/scatter_series.rb +2 -5
  42. data/lib/axlsx/drawing/ser_axis.rb +2 -6
  43. data/lib/axlsx/drawing/series.rb +3 -5
  44. data/lib/axlsx/drawing/series_title.rb +0 -2
  45. data/lib/axlsx/drawing/str_data.rb +3 -8
  46. data/lib/axlsx/drawing/str_val.rb +2 -5
  47. data/lib/axlsx/drawing/title.rb +12 -15
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +5 -7
  49. data/lib/axlsx/drawing/val_axis.rb +1 -4
  50. data/lib/axlsx/drawing/view_3D.rb +24 -24
  51. data/lib/axlsx/drawing/vml_drawing.rb +2 -5
  52. data/lib/axlsx/drawing/vml_shape.rb +4 -7
  53. data/lib/axlsx/package.rb +35 -36
  54. data/lib/axlsx/rels/relationship.rb +21 -24
  55. data/lib/axlsx/rels/relationships.rb +3 -6
  56. data/lib/axlsx/stylesheet/border.rb +1 -4
  57. data/lib/axlsx/stylesheet/border_pr.rb +3 -5
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +2 -10
  59. data/lib/axlsx/stylesheet/cell_protection.rb +1 -4
  60. data/lib/axlsx/stylesheet/cell_style.rb +3 -7
  61. data/lib/axlsx/stylesheet/color.rb +6 -5
  62. data/lib/axlsx/stylesheet/dxf.rb +2 -6
  63. data/lib/axlsx/stylesheet/fill.rb +0 -4
  64. data/lib/axlsx/stylesheet/font.rb +7 -6
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +4 -6
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +2 -3
  67. data/lib/axlsx/stylesheet/num_fmt.rb +1 -4
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +3 -5
  69. data/lib/axlsx/stylesheet/styles.rb +53 -45
  70. data/lib/axlsx/stylesheet/table_style.rb +5 -8
  71. data/lib/axlsx/stylesheet/table_style_element.rb +1 -4
  72. data/lib/axlsx/stylesheet/table_styles.rb +3 -7
  73. data/lib/axlsx/stylesheet/xf.rb +3 -6
  74. data/lib/axlsx/util/accessors.rb +2 -4
  75. data/lib/axlsx/util/constants.rb +3 -5
  76. data/lib/axlsx/util/mime_type_utils.rb +13 -0
  77. data/lib/axlsx/util/options_parser.rb +1 -2
  78. data/lib/axlsx/util/serialized_attributes.rb +4 -5
  79. data/lib/axlsx/util/simple_typed_list.rb +18 -17
  80. data/lib/axlsx/util/storage.rb +32 -36
  81. data/lib/axlsx/util/validators.rb +7 -4
  82. data/lib/axlsx/util/zip_command.rb +0 -2
  83. data/lib/axlsx/version.rb +1 -2
  84. data/lib/axlsx/workbook/defined_name.rb +6 -5
  85. data/lib/axlsx/workbook/defined_names.rb +1 -2
  86. data/lib/axlsx/workbook/shared_strings_table.rb +3 -6
  87. data/lib/axlsx/workbook/workbook.rb +96 -91
  88. data/lib/axlsx/workbook/workbook_view.rb +5 -10
  89. data/lib/axlsx/workbook/workbook_views.rb +1 -3
  90. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +9 -8
  91. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +6 -6
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +13 -14
  93. data/lib/axlsx/workbook/worksheet/border_creator.rb +29 -26
  94. data/lib/axlsx/workbook/worksheet/break.rb +2 -5
  95. data/lib/axlsx/workbook/worksheet/cell.rb +46 -26
  96. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +11 -11
  97. data/lib/axlsx/workbook/worksheet/cfvo.rb +2 -2
  98. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -5
  99. data/lib/axlsx/workbook/worksheet/col.rb +4 -7
  100. data/lib/axlsx/workbook/worksheet/col_breaks.rb +4 -5
  101. data/lib/axlsx/workbook/worksheet/color_scale.rb +10 -12
  102. data/lib/axlsx/workbook/worksheet/cols.rb +6 -6
  103. data/lib/axlsx/workbook/worksheet/comment.rb +4 -5
  104. data/lib/axlsx/workbook/worksheet/comments.rb +6 -10
  105. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +4 -5
  106. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +2 -6
  107. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +2 -4
  108. data/lib/axlsx/workbook/worksheet/data_bar.rb +20 -22
  109. data/lib/axlsx/workbook/worksheet/data_validation.rb +4 -5
  110. data/lib/axlsx/workbook/worksheet/data_validations.rb +2 -5
  111. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -3
  112. data/lib/axlsx/workbook/worksheet/dimension.rb +5 -4
  113. data/lib/axlsx/workbook/worksheet/header_footer.rb +0 -1
  114. data/lib/axlsx/workbook/worksheet/icon_set.rb +2 -3
  115. data/lib/axlsx/workbook/worksheet/merged_cells.rb +8 -8
  116. data/lib/axlsx/workbook/worksheet/outline_pr.rb +0 -1
  117. data/lib/axlsx/workbook/worksheet/page_margins.rb +2 -2
  118. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -3
  119. data/lib/axlsx/workbook/worksheet/page_setup.rb +117 -120
  120. data/lib/axlsx/workbook/worksheet/pane.rb +16 -17
  121. data/lib/axlsx/workbook/worksheet/pivot_table.rb +8 -11
  122. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -11
  123. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -4
  124. data/lib/axlsx/workbook/worksheet/print_options.rb +0 -1
  125. data/lib/axlsx/workbook/worksheet/protected_range.rb +4 -5
  126. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +9 -9
  127. data/lib/axlsx/workbook/worksheet/rich_text.rb +4 -6
  128. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +21 -5
  129. data/lib/axlsx/workbook/worksheet/row.rb +24 -15
  130. data/lib/axlsx/workbook/worksheet/row_breaks.rb +3 -4
  131. data/lib/axlsx/workbook/worksheet/selection.rb +7 -9
  132. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +5 -6
  133. data/lib/axlsx/workbook/worksheet/sheet_data.rb +4 -6
  134. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +18 -18
  135. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +4 -4
  136. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +12 -13
  137. data/lib/axlsx/workbook/worksheet/sheet_view.rb +35 -42
  138. data/lib/axlsx/workbook/worksheet/table.rb +7 -9
  139. data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -3
  140. data/lib/axlsx/workbook/worksheet/tables.rb +4 -4
  141. data/lib/axlsx/workbook/worksheet/worksheet.rb +63 -35
  142. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -6
  143. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +3 -2
  144. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +5 -6
  145. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -4
  146. data/lib/axlsx.rb +23 -9
  147. data/lib/caxlsx.rb +0 -1
  148. metadata +3 -3
@@ -1,8 +1,6 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # 3D attributes for a chart.
4
3
  class View3D
5
-
6
4
  include Axlsx::OptionsParser
7
5
 
8
6
  # Creates a new View3D for charts
@@ -12,8 +10,8 @@ module Axlsx
12
10
  # @option options [String] depth_percent
13
11
  # @option options [Boolean] r_ang_ax
14
12
  # @option options [Integer] perspective
15
- def initialize(options={})
16
- @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
13
+ def initialize(options = {})
14
+ @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
17
15
  parse_options options
18
16
  end
19
17
 
@@ -63,33 +61,33 @@ module Axlsx
63
61
  end
64
62
  alias :rotX= :rot_x=
65
63
 
66
- # @see h_percent
67
- def h_percent=(v)
68
- RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
69
- @h_percent = v
70
- end
64
+ # @see h_percent
65
+ def h_percent=(v)
66
+ RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
67
+ @h_percent = v
68
+ end
71
69
  alias :hPercent= :h_percent=
72
70
 
73
- # @see rot_y
74
- def rot_y=(v)
75
- RangeValidator.validate "View3D.rot_y", 0, 360, v
76
- @rot_y = v
77
- end
71
+ # @see rot_y
72
+ def rot_y=(v)
73
+ RangeValidator.validate "View3D.rot_y", 0, 360, v
74
+ @rot_y = v
75
+ end
78
76
  alias :rotY= :rot_y=
79
77
 
80
- # @see depth_percent
81
- def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
78
+ # @see depth_percent
79
+ def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
82
80
  alias :depthPercent= :depth_percent=
83
81
 
84
- # @see r_ang_ax
85
- def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
82
+ # @see r_ang_ax
83
+ def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
86
84
  alias :rAngAx= :r_ang_ax=
87
85
 
88
- # @see perspective
89
- def perspective=(v)
90
- RangeValidator.validate "View3D.perspective", 0, 240, v
91
- @perspective = v
92
- end
86
+ # @see perspective
87
+ def perspective=(v)
88
+ RangeValidator.validate "View3D.perspective", 0, 240, v
89
+ @perspective = v
90
+ end
93
91
 
94
92
  # DataTypeValidator.validate "#{self.class}.perspective", [Integer], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
95
93
 
@@ -105,10 +103,12 @@ module Axlsx
105
103
  end
106
104
 
107
105
  private
106
+
108
107
  # Note: move this to Axlsx module if we find the smae pattern elsewhere.
109
- def element_for_attribute(name, namespace='')
108
+ def element_for_attribute(name, namespace = '')
110
109
  val = Axlsx.instance_values_for(self)[name]
111
110
  return "" if val == nil
111
+
112
112
  "<%s:%s val='%s'/>" % [namespace, Axlsx::camel(name, false), val]
113
113
  end
114
114
  end
@@ -1,12 +1,11 @@
1
1
  module Axlsx
2
-
3
2
  # a vml drawing used for comments in excel.
4
3
  class VmlDrawing
5
-
6
4
  # creates a new Vml Drawing object.
7
5
  # @param [Comments] comments the comments object this drawing is associated with
8
6
  def initialize(comments)
9
7
  raise ArgumentError, "you must provide a comments object" unless comments.is_a?(Comments)
8
+
10
9
  @comments = comments
11
10
  end
12
11
 
@@ -25,7 +24,7 @@ module Axlsx
25
24
  xmlns:o="urn:schemas-microsoft-com:office:office"
26
25
  xmlns:x="urn:schemas-microsoft-com:office:excel">
27
26
  <o:shapelayout v:ext="edit">
28
- <o:idmap v:ext="edit" data="#{@comments.worksheet.index+1}"/>
27
+ <o:idmap v:ext="edit" data="#{@comments.worksheet.index + 1}"/>
29
28
  </o:shapelayout>
30
29
  <v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202"
31
30
  path="m0,0l0,21600,21600,21600,21600,0xe">
@@ -35,8 +34,6 @@ module Axlsx
35
34
  BAD_PROGRAMMER
36
35
  @comments.each { |comment| comment.vml_shape.to_xml_string str }
37
36
  str << "</xml>"
38
-
39
37
  end
40
-
41
38
  end
42
39
  end
@@ -1,8 +1,6 @@
1
1
  module Axlsx
2
-
3
2
  # A VmlShape is used to position and render a comment.
4
3
  class VmlShape
5
-
6
4
  include Axlsx::OptionsParser
7
5
  include Axlsx::Accessors
8
6
 
@@ -17,14 +15,14 @@ module Axlsx
17
15
  # @option options [Integer] right_offset
18
16
  # @option options [Integer] bottom_row
19
17
  # @option options [Integer] bottom_offset
20
- def initialize(options={})
18
+ def initialize(options = {})
21
19
  @row = @column = @left_column = @top_row = @right_column = @bottom_row = 0
22
20
  @left_offset = 15
23
21
  @top_offset = 2
24
22
  @right_offset = 50
25
23
  @bottom_offset = 5
26
24
  @visible = true
27
- @id = (0...8).map{65.+(rand(25)).chr}.join
25
+ @id = (0...8).map { 65.+(rand(25)).chr }.join
28
26
  parse_options options
29
27
  yield self if block_given?
30
28
  end
@@ -37,8 +35,8 @@ module Axlsx
37
35
  # serialize the shape to a string
38
36
  # @param [String] str
39
37
  # @return [String]
40
- def to_xml_string(str ='')
41
- str << <<SHAME_ON_YOU
38
+ def to_xml_string(str = '')
39
+ str << <<SHAME_ON_YOU
42
40
 
43
41
  <v:shape id="#{@id}" type="#_x0000_t202" fillcolor="#ffffa1 [80]" o:insetmode="auto"
44
42
  style="visibility:#{@visible ? 'visible' : 'hidden'}">
@@ -60,7 +58,6 @@ str << <<SHAME_ON_YOU
60
58
  </x:ClientData>
61
59
  </v:shape>
62
60
  SHAME_ON_YOU
63
-
64
61
  end
65
62
  end
66
63
  end
data/lib/axlsx/package.rb CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  module Axlsx
3
2
  # Package is responsible for managing all the bits and peices that Open Office XML requires to make a valid
4
3
  # xlsx document including validation and serialization.
@@ -20,7 +19,7 @@ module Axlsx
20
19
  # @option options [Time] :created_at Timestamp in the document properties (defaults to current time).
21
20
  # @option options [Boolean] :use_shared_strings This is passed to the workbook to specify that shared strings should be used when serializing the package.
22
21
  # @example Package.new :author => 'you!', :workbook => Workbook.new
23
- def initialize(options={})
22
+ def initialize(options = {})
24
23
  @workbook = nil
25
24
  @core, @app = Core.new, App.new
26
25
  @core.creator = options[:author] || @core.creator
@@ -36,8 +35,6 @@ module Axlsx
36
35
  workbook.use_autowidth = v
37
36
  end
38
37
 
39
-
40
-
41
38
  # Shortcut to determine if the workbook is configured to use shared strings
42
39
  # @see Workbook#use_shared_strings
43
40
  def use_shared_strings
@@ -50,6 +47,7 @@ module Axlsx
50
47
  Axlsx::validate_boolean(v);
51
48
  workbook.use_shared_strings = v
52
49
  end
50
+
53
51
  # The workbook this package will serialize or validate.
54
52
  # @return [Workbook] If no workbook instance has been assigned with this package a new Workbook instance is returned.
55
53
  # @raise ArgumentError if workbook parameter is not a Workbook instance.
@@ -102,11 +100,12 @@ module Axlsx
102
100
  # File.open('example_streamed.xlsx', 'wb') { |f| f.write(s.read) }
103
101
  def serialize(output, options = {}, secondary_options = nil)
104
102
  if !workbook.styles_applied
105
- workbook.apply_styles
103
+ workbook.apply_styles
106
104
  end
107
105
 
108
106
  confirm_valid, zip_command = parse_serialize_options(options, secondary_options)
109
107
  return false unless !confirm_valid || self.validate.empty?
108
+
110
109
  zip_provider = if zip_command
111
110
  ZipCommand.new(zip_command)
112
111
  else
@@ -121,16 +120,16 @@ module Axlsx
121
120
  Relationship.clear_ids_cache
122
121
  end
123
122
 
124
-
125
123
  # Serialize your workbook to a StringIO instance
126
124
  # @param [Boolean] confirm_valid Validate the package prior to serialization.
127
125
  # @return [StringIO|Boolean] False if confirm_valid and validation errors exist. rewound string IO if not.
128
- def to_stream(confirm_valid=false)
126
+ def to_stream(confirm_valid = false)
129
127
  if !workbook.styles_applied
130
- workbook.apply_styles
128
+ workbook.apply_styles
131
129
  end
132
130
 
133
131
  return false unless !confirm_valid || self.validate.empty?
132
+
134
133
  Relationship.initialize_ids_cache
135
134
  zip = write_parts(Zip::OutputStream.new(StringIO.new.binmode, true))
136
135
  stream = zip.close_buffer
@@ -187,7 +186,7 @@ module Axlsx
187
186
  end
188
187
  unless part[:path].nil?
189
188
  zip.put_next_entry(zip_entry_for_part(part))
190
- zip.write IO.read(part[:path], mode: "rb")
189
+ zip.write File.read(part[:path], mode: "rb")
191
190
  end
192
191
  end
193
192
  zip
@@ -214,30 +213,29 @@ module Axlsx
214
213
  # @private
215
214
  def parts
216
215
  parts = [
217
- {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles, :schema => SML_XSD},
218
- {:entry => CORE_PN, :doc => @core, :schema => CORE_XSD},
219
- {:entry => APP_PN, :doc => @app, :schema => APP_XSD},
220
- {:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships, :schema => RELS_XSD},
221
- {:entry => WORKBOOK_PN, :doc => workbook, :schema => SML_XSD}
216
+ { :entry => "xl/#{STYLES_PN}", :doc => workbook.styles, :schema => SML_XSD },
217
+ { :entry => CORE_PN, :doc => @core, :schema => CORE_XSD },
218
+ { :entry => APP_PN, :doc => @app, :schema => APP_XSD },
219
+ { :entry => WORKBOOK_RELS_PN, :doc => workbook.relationships, :schema => RELS_XSD },
220
+ { :entry => WORKBOOK_PN, :doc => workbook, :schema => SML_XSD }
222
221
  ]
223
222
 
224
223
  workbook.drawings.each do |drawing|
225
- parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships, :schema => RELS_XSD}
226
- parts << {:entry => "xl/#{drawing.pn}", :doc => drawing, :schema => DRAWING_XSD}
224
+ parts << { :entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships, :schema => RELS_XSD }
225
+ parts << { :entry => "xl/#{drawing.pn}", :doc => drawing, :schema => DRAWING_XSD }
227
226
  end
228
227
 
229
-
230
228
  workbook.tables.each do |table|
231
- parts << {:entry => "xl/#{table.pn}", :doc => table, :schema => SML_XSD}
229
+ parts << { :entry => "xl/#{table.pn}", :doc => table, :schema => SML_XSD }
232
230
  end
233
231
  workbook.pivot_tables.each do |pivot_table|
234
232
  cache_definition = pivot_table.cache_definition
235
- parts << {:entry => "xl/#{pivot_table.rels_pn}", :doc => pivot_table.relationships, :schema => RELS_XSD}
236
- parts << {:entry => "xl/#{pivot_table.pn}", :doc => pivot_table} #, :schema => SML_XSD}
237
- parts << {:entry => "xl/#{cache_definition.pn}", :doc => cache_definition} #, :schema => SML_XSD}
233
+ parts << { :entry => "xl/#{pivot_table.rels_pn}", :doc => pivot_table.relationships, :schema => RELS_XSD }
234
+ parts << { :entry => "xl/#{pivot_table.pn}", :doc => pivot_table } # , :schema => SML_XSD}
235
+ parts << { :entry => "xl/#{cache_definition.pn}", :doc => cache_definition } # , :schema => SML_XSD}
238
236
  end
239
237
 
240
- workbook.comments.each do|comment|
238
+ workbook.comments.each do |comment|
241
239
  if comment.size > 0
242
240
  parts << { :entry => "xl/#{comment.pn}", :doc => comment, :schema => SML_XSD }
243
241
  parts << { :entry => "xl/#{comment.vml_drawing.pn}", :doc => comment.vml_drawing, :schema => nil }
@@ -245,26 +243,26 @@ module Axlsx
245
243
  end
246
244
 
247
245
  workbook.charts.each do |chart|
248
- parts << {:entry => "xl/#{chart.pn}", :doc => chart, :schema => DRAWING_XSD}
246
+ parts << { :entry => "xl/#{chart.pn}", :doc => chart, :schema => DRAWING_XSD }
249
247
  end
250
248
 
251
249
  workbook.images.each do |image|
252
- parts << {:entry => "xl/#{image.pn}", :path => image.image_src}
250
+ parts << { :entry => "xl/#{image.pn}", :path => image.image_src } unless image.remote?
253
251
  end
254
252
 
255
253
  if use_shared_strings
256
- parts << {:entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings, :schema => SML_XSD}
254
+ parts << { :entry => "xl/#{SHARED_STRINGS_PN}", :doc => workbook.shared_strings, :schema => SML_XSD }
257
255
  end
258
256
 
259
257
  workbook.worksheets.each do |sheet|
260
- parts << {:entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships, :schema => RELS_XSD}
261
- parts << {:entry => "xl/#{sheet.pn}", :doc => sheet, :schema => SML_XSD}
258
+ parts << { :entry => "xl/#{sheet.rels_pn}", :doc => sheet.relationships, :schema => RELS_XSD }
259
+ parts << { :entry => "xl/#{sheet.pn}", :doc => sheet, :schema => SML_XSD }
262
260
  end
263
261
 
264
262
  # Sort parts for correct MIME detection
265
263
  [
266
- {:entry => CONTENT_TYPES_PN, :doc => content_types, :schema => CONTENT_TYPES_XSD},
267
- {:entry => RELS_PN, :doc => relationships, :schema => RELS_XSD},
264
+ { :entry => CONTENT_TYPES_PN, :doc => content_types, :schema => CONTENT_TYPES_XSD },
265
+ { :entry => RELS_PN, :doc => relationships, :schema => RELS_XSD },
268
266
  *(parts.sort_by { |part| part[:entry] }.reverse)
269
267
  ]
270
268
  end
@@ -314,8 +312,8 @@ module Axlsx
314
312
 
315
313
  workbook.comments.each do |comment|
316
314
  if comment.size > 0
317
- c_types << Axlsx::Override.new(:PartName => "/xl/#{comment.pn}",
318
- :ContentType => COMMENT_CT)
315
+ c_types << Axlsx::Override.new(:PartName => "/xl/#{comment.pn}",
316
+ :ContentType => COMMENT_CT)
319
317
  end
320
318
  end
321
319
 
@@ -325,18 +323,18 @@ module Axlsx
325
323
 
326
324
  workbook.worksheets.each do |sheet|
327
325
  c_types << Axlsx::Override.new(:PartName => "/xl/#{sheet.pn}",
328
- :ContentType => WORKSHEET_CT)
326
+ :ContentType => WORKSHEET_CT)
329
327
  end
330
328
  exts = workbook.images.map { |image| image.extname.downcase }
331
329
  exts.uniq.each do |ext|
332
- ct = if ['jpeg', 'jpg'].include?(ext)
330
+ ct = if ['jpeg', 'jpg'].include?(ext)
333
331
  JPEG_CT
334
332
  elsif ext == 'gif'
335
333
  GIF_CT
336
334
  elsif ext == 'png'
337
335
  PNG_CT
338
336
  end
339
- c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext )
337
+ c_types << Axlsx::Default.new(:ContentType => ct, :Extension => ext)
340
338
  end
341
339
  if use_shared_strings
342
340
  c_types << Axlsx::Override.new(:PartName => "/xl/#{SHARED_STRINGS_PN}",
@@ -379,7 +377,7 @@ module Axlsx
379
377
  def parse_serialize_options(options, secondary_options)
380
378
  if secondary_options
381
379
  warn "[DEPRECATION] Axlsx::Package#serialize with 3 arguments is deprecated. " +
382
- "Use keyword args instead e.g., package.serialize(output, confirm_valid: false, zip_command: 'zip')"
380
+ "Use keyword args instead e.g., package.serialize(output, confirm_valid: false, zip_command: 'zip')"
383
381
  end
384
382
  if options.is_a?(Hash)
385
383
  options.merge!(secondary_options || {})
@@ -387,10 +385,11 @@ module Axlsx
387
385
  if invalid_keys.any?
388
386
  raise ArgumentError.new("Invalid keyword arguments: #{invalid_keys}")
389
387
  end
388
+
390
389
  [options.fetch(:confirm_valid, false), options.fetch(:zip_command, nil)]
391
390
  else
392
391
  warn "[DEPRECATION] Axlsx::Package#serialize with confirm_valid as a boolean is deprecated. " +
393
- "Use keyword args instead e.g., package.serialize(output, confirm_valid: false)"
392
+ "Use keyword args instead e.g., package.serialize(output, confirm_valid: false)"
394
393
  parse_serialize_options((secondary_options || {}).merge(confirm_valid: options), nil)
395
394
  end
396
395
  end
@@ -1,9 +1,7 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # A relationship defines a reference between package parts.
4
3
  # @note Packages automatically manage relationships.
5
4
  class Relationship
6
-
7
5
  class << self
8
6
  # Keeps track of relationship ids in use.
9
7
  # @return [Array]
@@ -12,27 +10,27 @@ module Axlsx
12
10
  end
13
11
 
14
12
  # Initialize cached ids.
15
- #
13
+ #
16
14
  # This should be called before serializing a package (see {Package#serialize} and
17
- # {Package#to_stream}) to make sure that serialization is idempotent (i.e.
15
+ # {Package#to_stream}) to make sure that serialization is idempotent (i.e.
18
16
  # Relationship instances are generated with the same IDs everytime the package
19
17
  # is serialized).
20
18
  def initialize_ids_cache
21
19
  Thread.current[:axlsx_relationship_ids_cache] = {}
22
20
  end
23
-
21
+
24
22
  # Clear cached ids.
25
- #
23
+ #
26
24
  # This should be called after serializing a package (see {Package#serialize} and
27
25
  # {Package#to_stream}) to free the memory allocated for cache.
28
- #
29
- # Also, calling this avoids memory leaks (cached ids lingering around
30
- # forever).
26
+ #
27
+ # Also, calling this avoids memory leaks (cached ids lingering around
28
+ # forever).
31
29
  def clear_ids_cache
32
30
  Thread.current[:axlsx_relationship_ids_cache] = nil
33
31
  end
34
-
35
- # Generate and return a unique id (eg. `rId123`) Used for setting {#Id}.
32
+
33
+ # Generate and return a unique id (eg. `rId123`) Used for setting {#Id}.
36
34
  #
37
35
  # The generated id depends on the number of previously cached ids, so using
38
36
  # {clear_ids_cache} will automatically reset the generated ids, too.
@@ -42,12 +40,12 @@ module Axlsx
42
40
  end
43
41
  end
44
42
 
45
- # The id of the relationship (eg. "rId123"). Most instances get their own unique id.
43
+ # The id of the relationship (eg. "rId123"). Most instances get their own unique id.
46
44
  # However, some instances need to share the same id – see {#should_use_same_id_as?}
47
45
  # for details.
48
46
  # @return [String]
49
47
  attr_reader :Id
50
-
48
+
51
49
  # The location of the relationship target
52
50
  # @return [String]
53
51
  attr_reader :Target
@@ -77,16 +75,16 @@ module Axlsx
77
75
  # The source object the relations belongs to (e.g. a hyperlink, drawing, ...). Needed when
78
76
  # looking up the relationship for a specific object (see {Relationships#for}).
79
77
  attr_reader :source_obj
80
-
81
- # Initializes a new relationship.
78
+
79
+ # Initializes a new relationship.
82
80
  # @param [Object] source_obj see {#source_obj}
83
81
  # @param [String] type The type of the relationship
84
82
  # @param [String] target The target for the relationship
85
83
  # @option [Symbol] :target_mode only accepts :external.
86
- def initialize(source_obj, type, target, options={})
84
+ def initialize(source_obj, type, target, options = {})
87
85
  @source_obj = source_obj
88
- self.Target=target
89
- self.Type=type
86
+ self.Target = target
87
+ self.Type = type
90
88
  self.TargetMode = options[:target_mode] if options[:target_mode]
91
89
  @Id = (self.class.ids_cache[ids_cache_key] ||= self.class.next_free_id)
92
90
  end
@@ -103,17 +101,17 @@ module Axlsx
103
101
  # @param [String] str
104
102
  # @return [String]
105
103
  def to_xml_string(str = '')
106
- h = Axlsx.instance_values_for(self).reject{|k, _| k == "source_obj"}
104
+ h = Axlsx.instance_values_for(self).reject { |k, _| k == "source_obj" }
107
105
  str << '<Relationship '
108
- str << (h.map { |key, value| '' << key.to_s << '="' << Axlsx::coder.encode(value.to_s) << '"'}.join(' '))
106
+ str << (h.map { |key, value| '' << key.to_s << '="' << Axlsx::coder.encode(value.to_s) << '"' }.join(' '))
109
107
  str << '/>'
110
108
  end
111
-
109
+
112
110
  # A key that determines whether this relationship should use already generated id.
113
111
  #
114
112
  # Instances designating the same relationship need to use the same id. We can not simply
115
- # compare the {#Target} attribute, though: `foo/bar.xml`, `../foo/bar.xml`,
116
- # `../../foo/bar.xml` etc. are all different but probably mean the same file (this
113
+ # compare the {#Target} attribute, though: `foo/bar.xml`, `../foo/bar.xml`,
114
+ # `../../foo/bar.xml` etc. are all different but probably mean the same file (this
117
115
  # is especially an issue for relationships in the context of pivot tables). So lets
118
116
  # just ignore this attribute for now (except when {#TargetMode} is set to `:External` –
119
117
  # then {#Target} will be an absolute URL and thus can safely be compared).
@@ -125,6 +123,5 @@ module Axlsx
125
123
  key << self.Target if self.TargetMode == :External
126
124
  key
127
125
  end
128
-
129
126
  end
130
127
  end
@@ -1,11 +1,9 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
- require 'axlsx/rels/relationship.rb'
2
+ require 'axlsx/rels/relationship.rb'
4
3
 
5
4
  # Relationships are a collection of Relations that define how package parts are related.
6
5
  # @note The package automatically manages releationships.
7
6
  class Relationships < SimpleTypedList
8
-
9
7
  # Creates a new Relationships collection based on SimpleTypedList
10
8
  def initialize
11
9
  super Relationship
@@ -15,7 +13,7 @@ require 'axlsx/rels/relationship.rb'
15
13
  # @see Relationship#source_obj
16
14
  # @return [Relationship]
17
15
  def for(source_obj)
18
- find{ |rel| rel.source_obj == source_obj }
16
+ find { |rel| rel.source_obj == source_obj }
19
17
  end
20
18
 
21
19
  # serialize relationships
@@ -24,9 +22,8 @@ require 'axlsx/rels/relationship.rb'
24
22
  def to_xml_string(str = '')
25
23
  str << '<?xml version="1.0" encoding="UTF-8"?>'
26
24
  str << ('<Relationships xmlns="' << RELS_R << '">')
27
- each{ |rel| rel.to_xml_string(str) }
25
+ each { |rel| rel.to_xml_string(str) }
28
26
  str << '</Relationships>'
29
27
  end
30
-
31
28
  end
32
29
  end
@@ -1,8 +1,6 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # This class details a border used in Office Open XML spreadsheet styles.
4
3
  class Border
5
-
6
4
  include Axlsx::SerializedAttributes
7
5
  include Axlsx::OptionsParser
8
6
 
@@ -21,7 +19,7 @@ module Axlsx
21
19
  #
22
20
  # @note The recommended way to manage borders is with Style#add_style
23
21
  # @see Style#add_style
24
- def initialize(options={})
22
+ def initialize(options = {})
25
23
  @prs = SimpleTypedList.new BorderPr
26
24
  parse_options options
27
25
  end
@@ -68,6 +66,5 @@ module Axlsx
68
66
  end
69
67
  str << '</border>'
70
68
  end
71
-
72
69
  end
73
70
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # A border part.
4
3
  class BorderPr
@@ -44,11 +43,11 @@ module Axlsx
44
43
  # @option options [Symbol] name
45
44
  # @option options [Symbol] style
46
45
  # @see Axlsx::Border
47
- def initialize(options={})
46
+ def initialize(options = {})
48
47
  parse_options(options)
49
- #options.each do |o|
48
+ # options.each do |o|
50
49
  # self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
51
- #end
50
+ # end
52
51
  end
53
52
 
54
53
  # @see name
@@ -66,6 +65,5 @@ module Axlsx
66
65
  @color.to_xml_string(str) if @color.is_a?(Color)
67
66
  str << ('</' << @name.to_s << '>')
68
67
  end
69
-
70
68
  end
71
69
  end
@@ -1,16 +1,11 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
-
4
-
5
2
  # CellAlignment stores information about the cell alignment of a style Xf Object.
6
3
  # @note Using Styles#add_style is the recommended way to manage cell alignment.
7
4
  # @see Styles#add_style
8
5
  class CellAlignment
9
-
10
-
11
6
  include Axlsx::SerializedAttributes
12
7
  include Axlsx::OptionsParser
13
-
8
+
14
9
  serializable_attributes :horizontal, :vertical, :text_rotation, :wrap_text, :indent, :relative_indent, :justify_last_line, :shrink_to_fit, :reading_order
15
10
  # Create a new cell_alignment object
16
11
  # @option options [Symbol] horizontal
@@ -22,12 +17,10 @@ module Axlsx
22
17
  # @option options [Boolean] justify_last_line
23
18
  # @option options [Boolean] shrink_to_fit
24
19
  # @option options [Integer] reading_order
25
- def initialize(options={})
20
+ def initialize(options = {})
26
21
  parse_options options
27
22
  end
28
23
 
29
-
30
-
31
24
  # The horizontal alignment of the cell.
32
25
  # @note
33
26
  # The horizontal cell alignement style must be one of
@@ -127,6 +120,5 @@ module Axlsx
127
120
  def to_xml_string(str = '')
128
121
  serialized_tag('alignment', str)
129
122
  end
130
-
131
123
  end
132
124
  end
@@ -1,10 +1,8 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # CellProtection stores information about locking or hiding cells in spreadsheet.
4
3
  # @note Using Styles#add_style is the recommended way to manage cell protection.
5
4
  # @see Styles#add_style
6
5
  class CellProtection
7
-
8
6
  include Axlsx::OptionsParser
9
7
  include Axlsx::SerializedAttributes
10
8
 
@@ -21,7 +19,7 @@ module Axlsx
21
19
  # Creates a new CellProtection
22
20
  # @option options [Boolean] hidden value for hidden protection
23
21
  # @option options [Boolean] locked value for locked protection
24
- def initialize(options={})
22
+ def initialize(options = {})
25
23
  parse_options options
26
24
  end
27
25
 
@@ -36,6 +34,5 @@ module Axlsx
36
34
  def to_xml_string(str = '')
37
35
  serialized_tag('protection', str)
38
36
  end
39
-
40
37
  end
41
38
  end
@@ -1,10 +1,8 @@
1
- # encoding: UTF-8
2
1
  module Axlsx
3
2
  # CellStyle defines named styles that reference defined formatting records and can be used in your worksheet.
4
3
  # @note Using Styles#add_style is the recommended way to manage cell styling.
5
4
  # @see Styles#add_style
6
5
  class CellStyle
7
-
8
6
  include Axlsx::OptionsParser
9
7
  include Axlsx::SerializedAttributes
10
8
 
@@ -15,7 +13,7 @@ module Axlsx
15
13
  # @option options [Integer] iLevel
16
14
  # @option options [Boolean] hidden
17
15
  # @option options [Boolean] customBuiltIn
18
- def initialize(options={})
16
+ def initialize(options = {})
19
17
  parse_options options
20
18
  end
21
19
 
@@ -47,8 +45,8 @@ module Axlsx
47
45
  # @return [Boolean]
48
46
  attr_reader :customBuiltin
49
47
 
50
- # @see name
51
- def name=(v) Axlsx::validate_string v; @name = v end
48
+ # @see name
49
+ def name=(v) Axlsx::validate_string v; @name = v end
52
50
  # @see xfId
53
51
  def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
54
52
  # @see builtinId
@@ -66,7 +64,5 @@ module Axlsx
66
64
  def to_xml_string(str = '')
67
65
  serialized_tag('cellStyle', str)
68
66
  end
69
-
70
67
  end
71
-
72
68
  end