ooxml_excel 0.0.3.2 → 0.0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 650ed5f65217c586c53de12b5d1eafdaadb0d02a
4
- data.tar.gz: 72fab1922ac5014a570af54842613c33b244fcb1
3
+ metadata.gz: 6ada37077ee27fdaea8c64512a7abf812c0eff03
4
+ data.tar.gz: ff04e370268cec5b568cf99b67bc74cc7abedd65
5
5
  SHA512:
6
- metadata.gz: 4a62e204782cf8ae3346c504ee9b9df8afbed809c771d3f104ca8106c6be71100874a7d4b8a8ecdecf3cfb92eef8831ab30b2ebef0f320ec20e62044e4e7b87c
7
- data.tar.gz: 756f8984d194dbf7fc63f0abb12a31e039dfff964debe8a40243b8d6f8ff854668aa6e52208f3db3dbb3007f2d41448e4dfb22112fc58a203fa0bc715cee3841
6
+ metadata.gz: 29dd6544259f4b24a954842f929d400913964956646f0f05df2b8d554737b15267cc6a1af37f5143723f664554e460d31ae57f4f0abf4f3972b24d085ea4b0d6
7
+ data.tar.gz: 20a7af6b3bdb49be90ff77500c35dee10e9746d09e6baf8132679b7a986fbea9023443213121966495f512f7edb72705291d989415f875341033661f9290d7ed
data/README.md CHANGED
@@ -81,10 +81,10 @@ ooxml_excel.sheet('Test Sheet 1').column('A').hidden? # column letter
81
81
  ```
82
82
  # Font
83
83
  font_object = ooxml_excel.sheet('Test Sheet 1').font('A1')
84
- font.bold? # false
85
- font.name # Arial
86
- font.rgb_color # FFE10000
87
- font.size # 8
84
+ font_object.bold? # false
85
+ font_object.name # Arial
86
+ font_object.rgb_color # FFE10000
87
+ font_object.size # 8
88
88
 
89
89
  # Cell Fill
90
90
  fill_object = ooxml_excel.sheet('Test Sheet 1').fill('A1')
@@ -105,6 +105,9 @@ ooxml['Lists'!A1:A6] # ['1','2','3','4','5','6']
105
105
  # or loading a single value
106
106
  ooxml['Lists'!A1] # ['1']
107
107
 
108
+ # or loading a box type values
109
+ ooxml['Lists!A1:B2'] # [['1', '2'], ['2','3']]
110
+
108
111
  ```
109
112
  ### Fetching Data Validation
110
113
  ```
@@ -49,11 +49,27 @@ module OOXML
49
49
  cell_letters = formula.gsub(/[\d]/, '').split(':')
50
50
  start_index, end_index = formula.gsub(/[^\d:]/, '').split(':').map(&:to_i)
51
51
 
52
- cell_letter = cell_letters.uniq.first
53
- (start_index..end_index).to_a.map do |row_index|
54
- row = rows[row_index-1]
55
- next if row.blank?
56
- row["#{cell_letter}#{row_index}"].value
52
+ # This will allow values from this pattern
53
+ # 'SheetName!A1:C3'
54
+ # The number after the cell letter will be the index
55
+ # 1 => start_index
56
+ # 3 => end_index
57
+ # Expected output would be: [['value', 'value', 'value'], ['value', 'value', 'value'], ['value', 'value', 'value']]
58
+ if cell_letters.uniq.size > 1
59
+ start_index.upto(end_index).map do |row_index|
60
+ (cell_letters.first..cell_letters.last).map do |cell_letter|
61
+ row = rows[row_index-1]
62
+ next if row.blank?
63
+ row["#{cell_letter}#{row_index}"].value
64
+ end
65
+ end
66
+ else
67
+ cell_letter = cell_letters.uniq.first
68
+ (start_index..end_index).to_a.map do |row_index|
69
+ row = rows[row_index-1]
70
+ next if row.blank?
71
+ row["#{cell_letter}#{row_index}"].value
72
+ end
57
73
  end
58
74
  else
59
75
  # when only one value: B2
@@ -109,7 +109,7 @@ module OOXML
109
109
  raise 'Invalid Cell Reference!' if cell_reference[/[A-Z]{1,}\d+/].blank?
110
110
  row_index = cell_reference.scan(/[A-Z{1,}](\d+)/).flatten.first.to_i - 1
111
111
  return if rows[row_index].blank? || rows[row_index][cell_reference].blank?
112
- rows[row_index][cell_reference].s
112
+ rows[row_index][cell_reference].style_id
113
113
  end
114
114
 
115
115
  end
@@ -185,24 +185,24 @@ module OOXML
185
185
  end
186
186
 
187
187
  class Cell
188
- attr_accessor :id, :t, :s, :v, :shared_strings, :styles
189
- # t = type
190
- # v = value
191
- # s = style
188
+ attr_accessor :id, :type_id, :style_id, :value_id, :shared_strings, :styles
189
+
192
190
  def initialize(**attrs)
193
191
  attrs.each { |property, value| send("#{property}=", value)}
194
192
  end
195
193
 
196
194
  def type
197
- if t == 's'
198
- "string"
199
- elsif t == 'd'
200
- "date"
201
- elsif t == 'n'
202
- "number"
203
- else
204
- # TODO: git all types
205
- "string"
195
+ @type ||= begin
196
+ case type_id
197
+ when 's' then :string
198
+ when 'n' then :number
199
+ when 'b' then :boolean
200
+ when 'd' then :date
201
+ when 'str' then :formula
202
+ when 'inlineStr' then :inline_str
203
+ else
204
+ :error
205
+ end
206
206
  end
207
207
  end
208
208
 
@@ -230,18 +230,20 @@ module OOXML
230
230
  end
231
231
 
232
232
  def value
233
- if type == "number"
234
- v
233
+ case type
234
+ when :string
235
+ (value_id.present?) ? shared_strings[value_id.to_i] : nil
235
236
  else
236
- (v.present?) ? shared_strings[v.to_i] : nil
237
+ # TODO: to support other types soon
238
+ value_id
237
239
  end
238
240
  end
239
241
 
240
242
  def self.load_from_node(cell_node, shared_strings, styles)
241
243
  new(id: cell_node.attributes["r"].try(:value),
242
- t: cell_node.attributes["t"].try(:value),
243
- s: cell_node.attributes["s"].try(:value),
244
- v: cell_node.at('v').try(:text),
244
+ type_id: cell_node.attributes["t"].try(:value),
245
+ style_id: cell_node.attributes["s"].try(:value),
246
+ value_id: cell_node.at('v').try(:text),
245
247
  shared_strings: shared_strings,
246
248
  styles: styles )
247
249
  end
@@ -1,5 +1,5 @@
1
1
  module OOXML
2
2
  class Excel
3
- VERSION = "0.0.3.2"
3
+ VERSION = "0.0.3.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooxml_excel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.2
4
+ version: 0.0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mones
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-30 00:00:00.000000000 Z
11
+ date: 2016-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport