axlsx 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/README.md +13 -5
  2. data/examples/colored_links.rb +59 -0
  3. data/examples/example.rb +421 -266
  4. data/examples/example.xlsx +0 -0
  5. data/examples/example_streamed.xlsx +0 -0
  6. data/examples/finance.rb +82 -0
  7. data/examples/finance.xlsx +0 -0
  8. data/examples/financial.xlsx +0 -0
  9. data/examples/no-use_autowidth.xlsx +0 -0
  10. data/examples/shared_strings_example.xlsx +0 -0
  11. data/examples/where_is_my_color.xlsx +0 -0
  12. data/lib/axlsx.rb +11 -4
  13. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  14. data/lib/axlsx/content_type/content_type.rb +1 -1
  15. data/lib/axlsx/content_type/default.rb +6 -37
  16. data/lib/axlsx/content_type/override.rb +6 -38
  17. data/lib/axlsx/doc_props/app.rb +7 -4
  18. data/lib/axlsx/drawing/axis.rb +3 -3
  19. data/lib/axlsx/drawing/chart.rb +2 -3
  20. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  21. data/lib/axlsx/drawing/drawing.rb +6 -0
  22. data/lib/axlsx/drawing/hyperlink.rb +40 -32
  23. data/lib/axlsx/drawing/marker.rb +13 -13
  24. data/lib/axlsx/drawing/num_data.rb +6 -6
  25. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  26. data/lib/axlsx/drawing/one_cell_anchor.rb +20 -22
  27. data/lib/axlsx/drawing/pic.rb +25 -27
  28. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  29. data/lib/axlsx/drawing/scaling.rb +13 -13
  30. data/lib/axlsx/drawing/scatter_chart.rb +3 -3
  31. data/lib/axlsx/drawing/series.rb +3 -6
  32. data/lib/axlsx/drawing/str_data.rb +3 -3
  33. data/lib/axlsx/drawing/str_val.rb +7 -8
  34. data/lib/axlsx/drawing/view_3D.rb +51 -37
  35. data/lib/axlsx/drawing/vml_shape.rb +23 -23
  36. data/lib/axlsx/package.rb +14 -16
  37. data/lib/axlsx/stylesheet/border.rb +29 -20
  38. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  39. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  40. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  41. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  42. data/lib/axlsx/stylesheet/color.rb +19 -16
  43. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  44. data/lib/axlsx/stylesheet/font.rb +22 -22
  45. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  46. data/lib/axlsx/stylesheet/num_fmt.rb +22 -13
  47. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  48. data/lib/axlsx/stylesheet/styles.rb +1 -1
  49. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  50. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  51. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  52. data/lib/axlsx/stylesheet/xf.rb +28 -26
  53. data/lib/axlsx/util/accessors.rb +49 -0
  54. data/lib/axlsx/util/options_parser.rb +15 -0
  55. data/lib/axlsx/util/serialized_attributes.rb +46 -0
  56. data/lib/axlsx/util/simple_typed_list.rb +16 -4
  57. data/lib/axlsx/version.rb +1 -1
  58. data/lib/axlsx/workbook/defined_name.rb +13 -58
  59. data/lib/axlsx/workbook/workbook.rb +27 -1
  60. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -19
  61. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +20 -27
  62. data/lib/axlsx/workbook/worksheet/cell.rb +38 -39
  63. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  64. data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -0
  65. data/lib/axlsx/workbook/worksheet/col.rb +34 -27
  66. data/lib/axlsx/workbook/worksheet/color_scale.rb +7 -13
  67. data/lib/axlsx/workbook/worksheet/comment.rb +14 -11
  68. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  69. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +27 -25
  70. data/lib/axlsx/workbook/worksheet/data_bar.rb +44 -34
  71. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  72. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  73. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  74. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  75. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -9
  76. data/lib/axlsx/workbook/worksheet/page_setup.rb +20 -19
  77. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  78. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  79. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  80. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  81. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -26
  82. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +19 -57
  83. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  84. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  85. data/lib/axlsx/workbook/worksheet/table.rb +16 -18
  86. data/lib/axlsx/workbook/worksheet/table_style_info.rb +10 -27
  87. data/lib/axlsx/workbook/worksheet/worksheet.rb +6 -7
  88. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  89. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +11 -33
  90. data/test/content_type/tc_default.rb +0 -11
  91. data/test/content_type/tc_override.rb +0 -13
  92. data/test/drawing/tc_d_lbls.rb +14 -4
  93. data/test/tc_axlsx.rb +20 -2
  94. data/test/workbook/tc_defined_name.rb +2 -2
  95. data/test/workbook/tc_workbook.rb +15 -0
  96. data/test/workbook/worksheet/tc_col.rb +11 -1
  97. data/test/workbook/worksheet/tc_pane.rb +5 -45
  98. data/test/workbook/worksheet/tc_selection.rb +9 -48
  99. metadata +13 -3
@@ -43,16 +43,16 @@ module Axlsx
43
43
  def to_ary
44
44
  @list
45
45
  end
46
-
46
+
47
47
  alias :to_a :to_ary
48
-
48
+
49
49
  # Unlock the list
50
50
  # @return [self]
51
51
  def unlock
52
52
  @locked_at = nil
53
53
  self
54
54
  end
55
-
55
+
56
56
  # join operator
57
57
  # @param [Array] v the array to join
58
58
  # @raise [ArgumentError] if any of the values being joined are not
@@ -62,7 +62,7 @@ module Axlsx
62
62
  v.each do |item|
63
63
  DataTypeValidator.validate "SimpleTypedList.+", @allowed_types, item
64
64
  @list << item
65
- end
65
+ end
66
66
  end
67
67
 
68
68
  # Concat operator
@@ -107,6 +107,18 @@ module Axlsx
107
107
  v
108
108
  end
109
109
 
110
+ # inserts an item at the index specfied
111
+ # @param [Integer] index
112
+ # @param [Any] v
113
+ # @raise [ArgumentError] if the index is protected by locking
114
+ # @raise [ArgumentError] if the index is not one of the allowed types
115
+ def insert(index, v)
116
+ DataTypeValidator.validate "SimpleTypedList.<<", @allowed_types, v
117
+ raise ArgumentError, "Item is protected and cannot be changed" if protected? index
118
+ @list.insert(index, v)
119
+ v
120
+ end
121
+
110
122
  # determines if the index is protected
111
123
  # @param [Integer] index
112
124
  def protected? index
@@ -1,5 +1,5 @@
1
1
  module Axlsx
2
2
 
3
3
  # The current version
4
- VERSION = "1.3.1"
4
+ VERSION = "1.3.2"
5
5
  end
@@ -49,12 +49,15 @@ module Axlsx
49
49
  # @example
50
50
  # For clarification: LOG10 is always a cell reference, LOG10() is always formula, LOGO1000 can be a defined name that overrides a cell reference.
51
51
  class DefinedName
52
+ include Axlsx::SerializedAttributes
53
+ include Axlsx::OptionsParser
54
+ include Axlsx::Accessors
52
55
  # creates a new DefinedName.
53
56
  # @param [String] formula - the formula the defined name references
54
57
  # @param [Hash] options - A hash of key/value pairs that will be mapped to this instances attributes.
55
- #
58
+ #
56
59
  # @option [String] name - Specifies the name that appears in the user interface for the defined name.
57
- # This attribute is required.
60
+ # This attribute is required.
58
61
  # The following built-in names are defined in this SpreadsheetML specification:
59
62
  # Print
60
63
  # _xlnm.Print_Area: this defined name specifies the workbook's print area.
@@ -96,10 +99,9 @@ module Axlsx
96
99
  # version of the workbook that is published to or rendered on a Web or application server.
97
100
  def initialize(formula, options={})
98
101
  @formula = formula
99
- options.each do |o|
100
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
101
- end
102
+ parse_options options
102
103
  end
104
+
103
105
  attr_reader :local_sheet_id
104
106
 
105
107
  # The local sheet index (0-based)
@@ -109,64 +111,17 @@ module Axlsx
109
111
  @local_sheet_id = value
110
112
  end
111
113
 
112
- # string attributes that will be added when this class is evaluated
113
- STRING_ATTRIBUTES = [:short_cut_key, :status_bar, :help, :description, :custom_menu, :comment]
114
-
115
- # boolean attributes that will be added when this class is evaluated
116
- BOOLEAN_ATTRIBUTES = [:workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden]
117
-
118
- # Dynamically create string attribute accessors
119
- STRING_ATTRIBUTES.each do |attr|
120
- class_eval %{
121
- # The #{attr} attribute reader
122
- # @return [String]
123
- attr_reader :#{attr}
124
-
125
- # The #{attr} writer
126
- # @param [String] value The value to assign to #{attr}
127
- # @return [String]
128
- def #{attr}=(value)
129
- Axlsx::validate_string(value)
130
- @#{attr}= value
131
- end
132
- }
133
- end
134
-
135
- # Dynamically create boolean attribute accessors
136
- BOOLEAN_ATTRIBUTES.each do |attr|
137
- class_eval %{
138
- # The #{attr} attribute reader
139
- # @return [Boolean]
140
- attr_reader :#{attr}
114
+ string_attr_accessor :short_cut_key, :status_bar, :help, :description, :custom_menu, :comment, :name, :formula
141
115
 
142
- # The #{attr} writer
143
- # @param [Boolean] value The value to assign to #{attr}
144
- # @return [Boolean]
145
- def #{attr}=(value)
146
- Axlsx::validate_boolean(value)
147
- @#{attr} = value
148
- end
149
- }
150
- end
151
-
152
- attr_reader :name
153
- # The name of this defined name. Please refer to the class documentation for more information
154
- def name=(value)
155
- Axlsx::RestrictionValidator.validate 'DefinedName.name', %w(_xlnm.Print_Area _xlnm.Print_Titles _xlnm.Criteria _xlnm._FilterDatabase _xlnm.Extract _xlnm.Consolidate_Area _xlnm.Database _xlnm.Sheet_Title), value
156
- @name = value
157
- end
116
+ boolean_attr_accessor :workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden
158
117
 
159
- # The formula this defined name references
160
- attr_reader :formula
118
+ serializable_attributes :short_cut_key, :status_bar, :help, :description, :custom_menu, :comment,
119
+ :workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden, :name, :local_sheet_id
161
120
 
162
121
  def to_xml_string(str='')
163
122
  raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name
164
- str << '<definedName'
165
- instance_values.each do |name, value|
166
- unless name == 'formula'
167
- str << ' ' << Axlsx::camel(name, false) << "='#{value}'"
168
- end
169
- end
123
+ str << '<definedName '
124
+ serialized_attributes str
170
125
  str << '>' << @formula
171
126
  str << '</definedName>'
172
127
  end
@@ -11,6 +11,7 @@ require 'axlsx/workbook/worksheet/page_set_up_pr.rb'
11
11
  require 'axlsx/workbook/worksheet/page_setup.rb'
12
12
  require 'axlsx/workbook/worksheet/print_options.rb'
13
13
  require 'axlsx/workbook/worksheet/cfvo.rb'
14
+ require 'axlsx/workbook/worksheet/cfvos.rb'
14
15
  require 'axlsx/workbook/worksheet/color_scale.rb'
15
16
  require 'axlsx/workbook/worksheet/data_bar.rb'
16
17
  require 'axlsx/workbook/worksheet/icon_set.rb'
@@ -152,6 +153,14 @@ require 'axlsx/workbook/worksheet/selection.rb'
152
153
  @@date1904 = false
153
154
 
154
155
 
156
+ # A quick helper to retrive a worksheet by name
157
+ # @param [String] name The name of the sheet you are looking for
158
+ # @return [Worksheet] The sheet found, or nil
159
+ def sheet_by_name(name)
160
+ index = @worksheets.index { |sheet| sheet.name == name }
161
+ @worksheets[index] if index
162
+ end
163
+
155
164
  # lets come back to this later when we are ready for parsing.
156
165
  #def self.parse entry
157
166
  # io = entry.get_input_stream
@@ -160,7 +169,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
160
169
  # w.parse_string :date1904, "//xmlns:workbookPr/@date1904"
161
170
  # w
162
171
  #end
163
-
172
+
164
173
  # Creates a new Workbook
165
174
  # The recomended way to work with workbooks is via Package#workbook
166
175
  # @option options [Boolean] date1904. If this is not specified, date1904 is set to false. Office 2011 for Mac defaults to false.
@@ -206,6 +215,23 @@ require 'axlsx/workbook/worksheet/selection.rb'
206
215
  # see @use_autowidth
207
216
  def use_autowidth=(v=true) Axlsx::validate_boolean v; @use_autowidth = v; end
208
217
 
218
+ # inserts a worksheet into this workbook at the position specified.
219
+ # It the index specified is out of range, the worksheet will be added to the end of the
220
+ # worksheets collection
221
+ # @return [Worksheet]
222
+ # @param index The zero based position to insert the newly created worksheet
223
+ # @param [Hash] options Options to pass into the worksheed during initialization.
224
+ # @option options [String] name The name of the worksheet
225
+ # @option options [Hash] page_margins The page margins for the worksheet
226
+ def insert_worksheet(index=0, options={})
227
+ worksheet = Worksheet.new(self, options)
228
+ @worksheets.delete_at(@worksheets.size - 1)
229
+ @worksheets.insert(index, worksheet)
230
+ yield worksheet if block_given?
231
+ worksheet
232
+ end
233
+
234
+ #
209
235
  # Adds a worksheet to this workbook
210
236
  # @return [Worksheet]
211
237
  # @option options [String] name The name of the worksheet.
@@ -5,8 +5,8 @@ module Axlsx
5
5
  # then there is no corresponding filterColumn collection expressed for that column.
6
6
  class FilterColumn
7
7
 
8
- # Allowed filters
9
- FILTERS = [:filters] #, :top10, :custom_filters, :dynamic_filters, :color_filters, :icon_filters]
8
+ include Axlsx::OptionsParser
9
+ include Axlsx::SerializedAttributes
10
10
 
11
11
  # Creates a new FilterColumn object
12
12
  # @note This class yeilds its filter object as that is where the vast majority of processing will be done
@@ -19,17 +19,20 @@ module Axlsx
19
19
  RestrictionValidator.validate 'FilterColumn.filter', FILTERS, filter_type
20
20
  #Axlsx::validate_unsigned_int(col_id)
21
21
  self.col_id = col_id
22
- options.each do |o|
23
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
24
- end
22
+ parse_options options
25
23
  @filter = Axlsx.const_get(Axlsx.camel(filter_type)).new(options)
26
24
  yield @filter if block_given?
27
25
  end
28
26
 
27
+ serializable_attributes :col_id, :hidden_button, :show_button
28
+
29
+ # Allowed filters
30
+ FILTERS = [:filters] #, :top10, :custom_filters, :dynamic_filters, :color_filters, :icon_filters]
31
+
29
32
  # Zero-based index indicating the AutoFilter column to which this filter information applies.
30
33
  # @return [Integer]
31
34
  attr_reader :col_id
32
-
35
+
33
36
  # The actual filter being dealt with here
34
37
  # This could be any one of the allowed filter types
35
38
  attr_reader :filter
@@ -42,7 +45,7 @@ module Axlsx
42
45
  @show_button ||= true
43
46
  end
44
47
 
45
- # Flag indicating whether the AutoFilter button for this column is hidden.
48
+ # Flag indicating whether the AutoFilter button for this column is hidden.
46
49
  # @return [Boolean]
47
50
  def hidden_button
48
51
  @hidden_button ||= false
@@ -62,7 +65,7 @@ module Axlsx
62
65
  # @param [Array] row A row from a worksheet that needs to be
63
66
  # filtered.
64
67
  def apply(row, offset)
65
- row.hidden = @filter.apply(row.cells[offset+col_id.to_i])
68
+ row.hidden = @filter.apply(row.cells[offset+col_id.to_i])
66
69
  end
67
70
  # @param [Boolean] hidden Flag indicating whether the AutoFilter button for this column is hidden.
68
71
  # @return [Boolean]
@@ -87,16 +90,5 @@ module Axlsx
87
90
  @filter.to_xml_string(str)
88
91
  str << "</filterColumn>"
89
92
  end
90
-
91
- private
92
-
93
- def serialized_attributes(str='')
94
- instance_values.each do |key, value|
95
- if %(show_button hidden_button col_id).include? key.to_s
96
- str << "#{Axlsx.camel(key, false)}='#{value}' "
97
- end
98
- end
99
- str
100
- end
101
93
  end
102
94
  end
@@ -3,9 +3,8 @@ module Axlsx
3
3
  # When multiple values are chosen to filter by, or when a group of date values are chosen to filter by,
4
4
  # this object groups those criteria together.
5
5
  class Filters
6
-
7
- # Allowed calendar types
8
- CALENDAR_TYPES = %w(gregorian gregorianUs gregorianMeFrench gregorianArabic hijri hebrew taiwan japan thai korea saka gregorianXlitEnglish gregorianXlitFrench none)
6
+ include Axlsx::OptionsParser
7
+ include Axlsx::SerializedAttributes
9
8
 
10
9
  # Creates a new Filters object
11
10
  # @param [Hash] options Options used to set this objects attributes and
@@ -18,11 +17,14 @@ module Axlsx
18
17
  # @example
19
18
  # ws.auto_filter.add_column(0, :filters, :blank => true, :calendar_type => 'japan', :filter_items => [100, 'a'])
20
19
  def initialize(options={})
21
- options.each do |key, value|
22
- self.send("#{key}=", value) if self.respond_to? "#{key}="
23
- end
20
+ parse_options options
24
21
  end
25
22
 
23
+ serializable_attributes :blank, :calendar_type
24
+
25
+ # Allowed calendar types
26
+ CALENDAR_TYPES = %w(gregorian gregorianUs gregorianMeFrench gregorianArabic hijri hebrew taiwan japan thai korea saka gregorianXlitEnglish gregorianXlitFrench none)
27
+
26
28
  # Flag indicating whether to filter by blank.
27
29
  # @return [Boolean]
28
30
  attr_reader :blank
@@ -45,7 +47,7 @@ module Axlsx
45
47
  end
46
48
  true
47
49
  end
48
-
50
+
49
51
  # The filter values in this filters object
50
52
  def filter_items
51
53
  @filter_items ||= []
@@ -100,17 +102,6 @@ module Axlsx
100
102
  end
101
103
  end
102
104
 
103
- private
104
-
105
- def serialized_attributes(str='')
106
- instance_values.each do |key, value|
107
- if %(blank claendar_type).include? key.to_s
108
- str << "#{Axlsx.camel(key, false)}='#{value}' "
109
- end
110
- end
111
- str
112
- end
113
-
114
105
  # This class expresses a filter criteria value.
115
106
  class Filter
116
107
 
@@ -140,9 +131,8 @@ module Axlsx
140
131
  # subsequent dates, even when formatted or represented by other calendar
141
132
  # types, can be correctly compared for the purposes of filtering.
142
133
  class DateGroupItem
143
-
144
- # Allowed date time groupings
145
- DATE_TIME_GROUPING = %w(year month day hour minute second)
134
+ include Axlsx::OptionsParser
135
+ include Axlsx::SerializedAttributes
146
136
 
147
137
  # Creates a new DateGroupItem
148
138
  # @param [Hash] options A hash of options to use when
@@ -158,11 +148,14 @@ module Axlsx
158
148
  def initialize(options={})
159
149
  raise ArgumentError, "You must specify a year for date time grouping" unless options[:year]
160
150
  raise ArgumentError, "You must specify a date_time_grouping when creating a DateGroupItem for auto filter" unless options[:date_time_grouping]
161
- options.each do |key, value|
162
- self.send("#{key}=", value) if self.respond_to?("#{key}=")
163
- end
151
+ parse_options options
164
152
  end
165
153
 
154
+ serializable_attributes :date_time_grouping, :year, :month, :day, :hour, :minute, :second
155
+
156
+ # Allowed date time groupings
157
+ DATE_TIME_GROUPING = %w(year month day hour minute second)
158
+
166
159
  # Grouping level
167
160
  # This must be one of year, month, day, hour, minute or second.
168
161
  # @return [String]
@@ -224,8 +217,8 @@ module Axlsx
224
217
  # The minute value for the date group item
225
218
  # This must be between 0 and 59
226
219
  def minute=(value)
227
- RangeValidator.validate "DateGroupItem.minute", 0, 59, value
228
- @minute = value
220
+ RangeValidator.validate "DateGroupItem.minute", 0, 59, value
221
+ @minute = value
229
222
  end
230
223
 
231
224
  # The second value for the date group item
@@ -245,7 +238,7 @@ module Axlsx
245
238
  # @param [String] str The string object this serialization will be concatenated to.
246
239
  def to_xml_string(str = '')
247
240
  str << '<dateGroupItem '
248
- instance_values.each { |key, value| str << "#{key}='#{value.to_s}' " }
241
+ serialized_attributes str
249
242
  str << '/>'
250
243
  end
251
244
  end
@@ -8,6 +8,38 @@ module Axlsx
8
8
  # @see Worksheet#add_row
9
9
  class Cell
10
10
 
11
+ include Axlsx::OptionsParser
12
+
13
+ # @param [Row] row The row this cell belongs to.
14
+ # @param [Any] value The value associated with this cell.
15
+ # @option options [Symbol] type The intended data type for this cell. If not specified the data type will be determined internally based on the vlue provided.
16
+ # @option options [Integer] style The index of the cellXfs item to be applied to this cell. If not specified, the default style (0) will be applied.
17
+ # @option options [String] font_name
18
+ # @option options [Integer] charset
19
+ # @option options [String] family
20
+ # @option options [Boolean] b
21
+ # @option options [Boolean] i
22
+ # @option options [Boolean] strike
23
+ # @option options [Boolean] outline
24
+ # @option options [Boolean] shadow
25
+ # @option options [Boolean] condense
26
+ # @option options [Boolean] extend
27
+ # @option options [Boolean] u
28
+ # @option options [Symbol] vertAlign must be one of :baseline, :subscript, :superscript
29
+ # @option options [Integer] sz
30
+ # @option options [String] color an 8 letter rgb specification
31
+ # @option options [Symbol] scheme must be one of :none, major, :minor
32
+ def initialize(row, value="", options={})
33
+ self.row=row
34
+ @value = @font_name = @charset = @family = @b = @i = @strike = @outline = @shadow = nil
35
+ @condense = @u = @vertAlign = @sz = @color = @scheme = @extend = @ssti = nil
36
+ @styles = row.worksheet.workbook.styles
37
+ @row.cells << self
38
+ parse_options options
39
+ @style ||= 0
40
+ @type ||= cell_type_from_value(value)
41
+ @value = cast_value(value)
42
+ end
11
43
 
12
44
  # An array of available inline styes.
13
45
  # TODO change this to a hash where each key defines attr name and validator (and any info the validator requires)
@@ -16,9 +48,9 @@ module Axlsx
16
48
  # set_attr method that kicks the suplied validator and updates the instance_variable
17
49
  # for the key
18
50
  INLINE_STYLES = ['value', 'type', 'font_name', 'charset',
19
- 'family', 'b', 'i', 'strike','outline',
20
- 'shadow', 'condense', 'extend', 'u',
21
- 'vertAlign', 'sz', 'color', 'scheme']
51
+ 'family', 'b', 'i', 'strike','outline',
52
+ 'shadow', 'condense', 'extend', 'u',
53
+ 'vertAlign', 'sz', 'color', 'scheme']
22
54
 
23
55
  # The index of the cellXfs item to be applied to this cell.
24
56
  # @return [Integer]
@@ -174,39 +206,6 @@ module Axlsx
174
206
  set_run_style nil, :scheme, v
175
207
  end
176
208
 
177
- # @param [Row] row The row this cell belongs to.
178
- # @param [Any] value The value associated with this cell.
179
- # @option options [Symbol] type The intended data type for this cell. If not specified the data type will be determined internally based on the vlue provided.
180
- # @option options [Integer] style The index of the cellXfs item to be applied to this cell. If not specified, the default style (0) will be applied.
181
- # @option options [String] font_name
182
- # @option options [Integer] charset
183
- # @option options [String] family
184
- # @option options [Boolean] b
185
- # @option options [Boolean] i
186
- # @option options [Boolean] strike
187
- # @option options [Boolean] outline
188
- # @option options [Boolean] shadow
189
- # @option options [Boolean] condense
190
- # @option options [Boolean] extend
191
- # @option options [Boolean] u
192
- # @option options [Symbol] vertAlign must be one of :baseline, :subscript, :superscript
193
- # @option options [Integer] sz
194
- # @option options [String] color an 8 letter rgb specification
195
- # @option options [Symbol] scheme must be one of :none, major, :minor
196
- def initialize(row, value="", options={})
197
- self.row=row
198
- @value = @font_name = @charset = @family = @b = @i = @strike = @outline = @shadow = nil
199
- @condense = @u = @vertAlign = @sz = @color = @scheme = @extend = @ssti = nil
200
- @styles = row.worksheet.workbook.styles
201
- @row.cells << self
202
- options.each do |o|
203
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
204
- end
205
- @style ||= 0
206
- @type ||= cell_type_from_value(value)
207
- @value = cast_value(value)
208
- end
209
-
210
209
  # The Shared Strings Table index for this cell
211
210
  # @return [Integer]
212
211
  attr_reader :ssti
@@ -346,9 +345,9 @@ module Axlsx
346
345
  # the cell itself. Yes, it is a bit of a hack, but it is much better than using
347
346
  # imagemagick and loading metrics for every character.
348
347
  def font_size
349
- font = @styles.fonts[@styles.cellXfs[style].fontId] || @styles.fonts[0]
350
- size_from_styles = (font.b || b) ? font.sz * 1.5 : font.sz
351
- sz || size_from_styles
348
+ font = @styles.fonts[@styles.cellXfs[style].fontId] || @styles.fonts[0]
349
+ size_from_styles = (font.b || b) ? font.sz * 1.5 : font.sz
350
+ sz || size_from_styles
352
351
  end
353
352
 
354
353
  # Utility method for setting inline style attributes