ooxml_excel 0.0.2 → 0.0.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: e5989596afa2991677b2986fc66c4aa8be2c24af
4
- data.tar.gz: ddffed3aadfe48b0f9a7d4c5299eed9a441dbe54
3
+ metadata.gz: db608f8f90704e4f7f3497890e3749cff05de557
4
+ data.tar.gz: b787c6251283d5faa92ec2760212b9d22e8c1049
5
5
  SHA512:
6
- metadata.gz: c6add5668d0617f49da6bf79f3c0dd3083ae797cfe9b2a75b844fea1091c6a396a6479ba443973b28bd74a0a7de1a6287692529b831b2816b30d320f830030b8
7
- data.tar.gz: 9ee8046efadb7a0fdf9b89a12f29e7e110b3819bb49f60f3ed9f06103246f4da5ae7748b5aeb0645dc99644ca3f9caa54da4f522fb39807ba83b5fc991e630c1
6
+ metadata.gz: e8b5f88a02e9b792321e4012d711ac85431c826b332b7546223ed9cecb79dd2544490c7fb8d1bdeda90935e10e01806f0a47b34bdd64a025ee4f21b8a72978b8
7
+ data.tar.gz: 7b4f356262e48233ecfd2f13508cb055457f8b2e1f012377e871b14e59e9be0fb3f2a15058e84e75b84b21fa37606738c06b5dd367b26633974a25b391e85497
data/README.md CHANGED
@@ -45,27 +45,29 @@ sheet.rows[0].cells # longer way to do it
45
45
  sheet[0][0] # Access the first cell of the row
46
46
  sheet.rows[0].cells[0] # longer way to do it
47
47
 
48
- sheet[0][0].value # Access cell values
48
+ sheet[0][0].value # Access cell value
49
49
  sheet.rows[0].cells[0].value # longer way to do it
50
50
 
51
+ ooxml_excel['Test Sheet 1'][0][0].value
51
52
  ```
52
53
 
53
- ### Iterating to each row:
54
+ ### Iterating through each row:
54
55
  ```
55
56
  # as an array of strings
56
57
  ooxml_excel.sheet('Test Sheet 1').each_row do |row|
57
58
  # Do something here...
59
+ p row # ['text', 'text']
58
60
  end
59
61
 
60
62
  # as an array of objects
61
63
  ooxml_excel.sheet('Test Sheet 1').each_row_as_object do |row|
62
64
  # Do something here...
63
- p row
65
+ p row.cells # [OOXML::Excel::Row::Cell, ...]
64
66
  end
65
67
 
66
68
  ```
67
69
 
68
- ### Fetching Columns:
70
+ ### Fetching Columns
69
71
  ```
70
72
  # Fetch all columns
71
73
  ooxml_excel.sheet('Test Sheet 1').columns
@@ -75,8 +77,7 @@ ooxml_excel.sheet('Test Sheet 1').column(1).hidden? # column index
75
77
  ooxml_excel.sheet('Test Sheet 1').column('A').hidden? # column letter
76
78
  ```
77
79
 
78
- ### Fetching Styles:
79
-
80
+ ### Fetching Styles
80
81
  ```
81
82
  # Font
82
83
  font_object = ooxml_excel.sheet('Test Sheet 1').font('A1')
@@ -90,8 +91,22 @@ fill_object = ooxml_excel.sheet('Test Sheet 1').fill('A1')
90
91
  fill_object.bg_color # FFE10000
91
92
  fill_object.fg_color # FFE10000
92
93
  ```
94
+ ### Fetching Data from named/cell range
95
+ ```
96
+ # named range
97
+ ooxml_excel.named_range('my_named_range') # ['value' 'from', 'range']
98
+
99
+ # cell range
100
+ ooxml['Lists'!$A$1:$A$6] # ['1','2','3','4','5','6']
93
101
 
94
- ### Data Validation
102
+ # or
103
+ ooxml['Lists'!A1:A6] # ['1','2','3','4','5','6']
104
+
105
+ # or loading a single value
106
+ ooxml['Lists'!A1] # ['1']
107
+
108
+ ```
109
+ ### Fetching Data Validation
95
110
  ```
96
111
  # All Validations
97
112
  data_validations = ooxml_excel.sheet('Test Sheet 1').data_validations
@@ -4,10 +4,10 @@ module OOXML
4
4
  attr_reader :comments
5
5
  def initialize(spreadsheet, load_only_sheet:nil)
6
6
  @spreadsheet = spreadsheet
7
+ @workbook = nil
7
8
  @sheets = {}
8
9
  @comments = {}
9
10
  # @themes = []
10
- @workbook = nil
11
11
  @load_only_sheet = nil
12
12
  @styles = nil
13
13
  load_xml_contents
@@ -30,8 +30,32 @@ module OOXML
30
30
  sheet
31
31
  end
32
32
 
33
+ def [](text)
34
+ # immediately treat as cell range if an exclamation point is detected
35
+ # otherwise, normally load a sheet
36
+ text.include?('!') ? load_list_values(text) : sheet(text)
37
+ end
38
+
39
+ def named_range(name)
40
+ # "Hidden11390550_39"=>"Hidden!$B$734:$B$735"
41
+ # ooxml.named_range('Hidden11390550_107')
42
+ # a typical named range would be be
43
+ # yes_no => 'Lists'!$A$1:$A$6
44
+ defined_name = @workbook.defined_names[name]
45
+ load_list_values(defined_name) if defined_name.present?
46
+ end
47
+
33
48
  private
34
49
 
50
+ def load_list_values(range_text)
51
+ # get the sheet name => 'Lists'
52
+ sheet_name = range_text.gsub(/[\$\']/, '').scan(/^[^!]*/).first
53
+ # fetch the cell range => '$A$1:$A$6'
54
+ cell_range = range_text.gsub(/\$/, '').scan(/(?<=!).+/).first
55
+ # get the sheet object and fetch the cells in range
56
+ sheet(sheet_name).list_values_from_formula(cell_range)
57
+ end
58
+
35
59
  # Currently supports DataValidation (comment), columns (check if hidden)
36
60
  # TODO: list values, Font styles (if bold, colored in red etc..), background color
37
61
  def load_xml_contents
@@ -4,6 +4,7 @@ module OOXML
4
4
 
5
5
  # excel.rb
6
6
  # fetch dropdown values based on given data validation formula
7
+ # this will be depracated: use #named_range instead
7
8
  def list_values(formula)
8
9
  # "Lists!$J$2:$J$4"
9
10
  # transform into useful info
@@ -1,5 +1,5 @@
1
1
  module OOXML
2
2
  class Excel
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooxml_excel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mones