ooxl 0.0.1.4.2 → 0.0.1.4.4

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: 3dbd162a56c9167fec434f9975d905a4dca69c79
4
- data.tar.gz: e483a49838c4f29346bac04ca5311d5ca8ba9ac2
3
+ metadata.gz: 151eec32fedade6ddda1ceb1640dd96ea21b27e3
4
+ data.tar.gz: 67e32ab6fa64205b3bdd8e130b441338f7cfface
5
5
  SHA512:
6
- metadata.gz: febc4c1834fccadc03de6ede23cec6426a7adc2efa1aa998b6fe59ffd819324d24ac74de8d3d56fbdb151e7a0e1117b4846626f560ab37870ced107fc7b140cb
7
- data.tar.gz: 2d9b0da9836a3d8481caa05a61f8a3233ba6f341642db6474d6e7b14187da2746cd0e265f644cd3f000f64fbe4f54e14a18908e811ece6a935985e0f79ea4d23
6
+ metadata.gz: 177c5802385bc0a0ce106c992379e91e2660db986990d4235a5a96aecbf647e2824dbcac06972ee5dd3f9c6e29b1bc8535b2702f98e0cfea7edb0887ec697dbb
7
+ data.tar.gz: b921d5b3e6aa9208d15fba79ad3c5fee5c6c92ba166a6ab9e221ac11d94079a03f0e8debcc83d015d5c59f2397725c72aa63f65bc8ff378a6e140f8b3a717f73
@@ -0,0 +1,26 @@
1
+ class OOXL
2
+ module ListHelper
3
+ # fetch dropdown values based on given data validation formula
4
+ def list_values(formula)
5
+ # "Lists!$J$2:$J$4"
6
+
7
+ # for list values explicitly stated
8
+ if formula.include?(',')
9
+ formula.gsub('"', '').split(',')
10
+ elsif !formula.include?('!') && formula[/$/]
11
+ puts "Warning: This formula is not yet supported: #{formula} in your Data Validation's formula."
12
+ []
13
+ else
14
+ # # required for fetching values
15
+ sheet_name = formula.gsub(/[\$\']/, '').scan(/^[^!]*/).first
16
+ cell_range = formula.gsub(/\$/, '').scan(/(?<=!).+/).first
17
+
18
+ # fetch the sheet of the cell reference
19
+ working_sheet = sheet(sheet_name)
20
+
21
+ # gather values
22
+ list_values = working_sheet.list_values_from_cell_range(cell_range)
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/ooxl/ooxl.rb CHANGED
@@ -1,21 +1,24 @@
1
1
  class OOXL
2
2
  include Enumerable
3
- def initialize(spreadsheet_filepath)
3
+ include ListHelper
4
+
5
+ def initialize(spreadsheet_filepath, options={})
4
6
  @workbook = nil
5
7
  @sheets = {}
6
8
  @styles = []
7
9
  @comments = {}
8
10
  @relationships = {}
11
+ @options = options
9
12
  parse_spreadsheet_contents(spreadsheet_filepath)
10
13
  end
11
14
 
12
- def self.open(spreadsheet_filepath)
13
- new(spreadsheet_filepath)
15
+ def self.open(spreadsheet_filepath, options={})
16
+ new(spreadsheet_filepath, options)
14
17
  end
15
18
 
16
19
  def sheets(skip_hidden: false)
17
20
  @workbook.sheets.map do |sheet|
18
- next if sheet[:state] != 'visible' && skip_hidden
21
+ next if sheet[:state] != 'visible' && (@options[:skip_hidden_sheets] || skip_hidden)
19
22
  sheet[:name]
20
23
  end.compact
21
24
  end
@@ -42,20 +45,16 @@ class OOXL
42
45
  def [](text)
43
46
  # immediately treat as cell range if an exclamation point is detected
44
47
  # otherwise, normally load a sheet
45
-
46
- text.include?('!') ? load_list_values(text) : sheet(text)
48
+ text.include?('!') ? load_cell_range(text) : sheet(text)
47
49
  end
48
50
 
49
51
  def named_range(name)
50
- # "Hidden11390550_39"=>"Hidden!$B$734:$B$735"
51
- # ooxml.named_range('Hidden11390550_107')
52
- # a typical named range would be be
53
52
  # yes_no => 'Lists'!$A$1:$A$6
54
53
  defined_name = @workbook.defined_names[name]
55
- load_list_values(defined_name) if defined_name.present?
54
+ load_cell_range(defined_name) if defined_name.present?
56
55
  end
57
56
 
58
- def load_list_values(range_text)
57
+ def load_cell_range(range_text)
59
58
  # get the sheet name => 'Lists'
60
59
  sheet_name = range_text.gsub(/[\$\']/, '').scan(/^[^!]*/).first
61
60
  # fetch the cell range => '$A$1:$A$6'
@@ -63,7 +62,6 @@ class OOXL
63
62
  # get the sheet object and fetch the cells in range
64
63
  sheet(sheet_name).list_values_from_cell_range(cell_range)
65
64
  end
66
- alias_method :list_values, :load_list_values
67
65
 
68
66
  def fetch_comments(sheet_index)
69
67
  final_sheet_index = sheet_index+1
data/lib/ooxl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class OOXL
2
- VERSION = "0.0.1.4.2"
2
+ VERSION = "0.0.1.4.4"
3
3
  end
@@ -10,6 +10,14 @@ class OOXL
10
10
  end
11
11
  end
12
12
 
13
+ # where,
14
+ # r = reference
15
+ # s = style
16
+ # t = type
17
+ # v = value
18
+ # <c r="A1" s="227" t="s">
19
+ # <v>113944</v>
20
+ # </c>
13
21
  class Cell
14
22
  attr_accessor :id, :type_id, :style_id, :value_id, :shared_strings, :styles
15
23
 
@@ -18,7 +26,7 @@ class OOXL
18
26
  end
19
27
 
20
28
  def next_id(offset: 1, location: "bottom")
21
- _, column_letter, column_index = id.partition(/[A-Z]/)
29
+ _, column_letter, column_index = id.partition(/[A-Z]+/)
22
30
 
23
31
  # ensure that all are numbers
24
32
  column_index = column_index.to_i
@@ -1,6 +1,6 @@
1
1
  class OOXL
2
2
  class Column
3
- attr_accessor :id, :width, :custom_width, :id_range, :hidden
3
+ attr_accessor :id, :width, :custom_width, :id_range, :hidden, :best_fit
4
4
  alias_method :hidden?, :hidden
5
5
 
6
6
  def initialize(**attrs)
@@ -11,9 +11,14 @@ class OOXL
11
11
  hidden_attr = column_node.attributes["hidden"]
12
12
  new(id: column_node.attributes["min"].try(:value),
13
13
  width: column_node.attributes["width"].try(:value),
14
+ best_fit: column_node.attributes["best_fit"].try(:value),
14
15
  custom_width: column_node.attributes["custom_width"].try(:value),
15
16
  id_range: (column_node.attributes["min"].value.to_i..column_node.attributes["max"].value.to_i).to_a,
16
17
  hidden: (hidden_attr.present?) ? hidden_attr.value == "1" : false)
17
18
  end
18
19
  end
19
20
  end
21
+
22
+ # <col min="3" max="3" width="6.42578125" bestFit="1" customWidth="1" />
23
+ # <col min="4" max="5" width="12.7109375" customWidth="1" />
24
+ # <col min="6" max="8" width="6.42578125" customWidth="1" />
@@ -22,7 +22,6 @@ class OOXL
22
22
  comment_text_node.text
23
23
  end
24
24
 
25
- # value = (comment_node.xpath('./text/r/t').last || comment_node.at_xpath('./text/r/t') || comment_node.at_xpath('./text/t')).text
26
25
  id = comment_node.attributes["ref"].to_s
27
26
  [id, value]
28
27
  end.to_h
@@ -30,3 +29,98 @@ class OOXL
30
29
  end
31
30
  end
32
31
  end
32
+
33
+
34
+ # <comments>
35
+ # <authors>
36
+ # <author>Author1</author>
37
+ # </authors>
38
+ # <commentList>
39
+ # <comment ref="J1" authorId="0" shapeId="0">
40
+ # <text>
41
+ # <r>
42
+ # <rPr>
43
+ # <sz val="8" />
44
+ # <color indexed="81" />
45
+ # <rFont val="Tahoma" />
46
+ # <family val="2" />
47
+ # </rPr>
48
+ # <t>Is the product weight consistent? ( Yes or No)</t>
49
+ # </r>
50
+ # </text>
51
+ # </comment>
52
+ # <comment ref="L1" authorId="0" shapeId="0">
53
+ # <text>
54
+ # <r>
55
+ # <rPr>
56
+ # <sz val="8" />
57
+ # <color indexed="81" />
58
+ # <rFont val="Tahoma" />
59
+ # <family val="2" />
60
+ # </rPr>
61
+ # <t xml:space="preserve">Enter weight of product without any packaging.
62
+ # </t>
63
+ # </r>
64
+ # </text>
65
+ # </comment>
66
+ # <comment ref="O1" authorId="0" shapeId="0">
67
+ # <text>
68
+ # <r>
69
+ # <rPr>
70
+ # <sz val="8" />
71
+ # <color indexed="81" />
72
+ # <rFont val="Tahoma" />
73
+ # <family val="2" />
74
+ # </rPr>
75
+ # <t>Number of days product can remain on store shelf.</t>
76
+ # </r>
77
+ # <r>
78
+ # <rPr>
79
+ # <sz val="8" />
80
+ # <color indexed="81" />
81
+ # <rFont val="Tahoma" />
82
+ # <family val="2" />
83
+ # </rPr>
84
+ # <t xml:space="preserve">
85
+ # </t>
86
+ # </r>
87
+ # </text>
88
+ # </comment>
89
+ # <comment ref="P1" authorId="0" shapeId="0">
90
+ # <text>
91
+ # <r>
92
+ # <rPr>
93
+ # <sz val="8" />
94
+ # <color indexed="81" />
95
+ # <rFont val="Tahoma" />
96
+ # <family val="2" />
97
+ # </rPr>
98
+ # <t>Total life of product in number of days (including shelf life).</t>
99
+ # </r>
100
+ # <r>
101
+ # <rPr>
102
+ # <sz val="8" />
103
+ # <color indexed="81" />
104
+ # <rFont val="Tahoma" />
105
+ # <family val="2" />
106
+ # </rPr>
107
+ # <t xml:space="preserve">
108
+ # </t>
109
+ # </r>
110
+ # </text>
111
+ # </comment>
112
+ # <comment ref="Q1" authorId="0" shapeId="0">
113
+ # <text>
114
+ # <r>
115
+ # <rPr>
116
+ # <sz val="8" />
117
+ # <color indexed="81" />
118
+ # <rFont val="Tahoma" />
119
+ # <family val="2" />
120
+ # </rPr>
121
+ # <t>Product packaging Weight only!</t>
122
+ # </r>
123
+ # </text>
124
+ # </comment>
125
+ # </commentList>
126
+ # </comments>
@@ -36,3 +36,14 @@ class OOXL
36
36
 
37
37
  end
38
38
  end
39
+
40
+ # Only supporting comments for now
41
+
42
+ # <Relationships>
43
+ # <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing" Target="../drawings/vmlDrawing1.vml" />
44
+ # <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing" Target="../drawings/drawing1.xml" />
45
+ # <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customProperty" Target="../customProperty1.bin" />
46
+ # <Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" Target="../comments1.xml" />
47
+ # <Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp" Target="../ctrlProps/ctrlProp2.xml" />
48
+ # <Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/ctrlProp" Target="../ctrlProps/ctrlProp1.xml" />
49
+ # </Relationships>
@@ -27,3 +27,7 @@ class OOXL
27
27
  end
28
28
  end
29
29
  end
30
+
31
+ # <row r="1" spans="1:38" s="111" customFormat="1" ht="75" x14ac:dyDescent="0.2">
32
+ # <c r="A1" s="108" t="s">
33
+ # </row>
@@ -17,3 +17,10 @@ class OOXL
17
17
  end
18
18
  end
19
19
  end
20
+
21
+ # <cellStyleXfs count="4">
22
+ # <xf numFmtId="0" fontId="0" fillId="0" borderId="0" />
23
+ # <xf numFmtId="0" fontId="1" fillId="0" borderId="0" />
24
+ # <xf numFmtId="0" fontId="39" fillId="0" borderId="0" applyProtection="0" />
25
+ # <xf numFmtId="9" fontId="1" fillId="0" borderId="0" applyFont="0" applyFill="0" applyBorder="0" applyAlignment="0" applyProtection="0" />
26
+ # </cellStyleXfs>
@@ -29,3 +29,48 @@ class OOXL
29
29
  end
30
30
  end
31
31
  end
32
+
33
+ # <fills count="9">
34
+ # <fill>
35
+ # <patternFill patternType="none" />
36
+ # </fill>
37
+ # <fill>
38
+ # <patternFill patternType="gray125" />
39
+ # </fill>
40
+ # <fill>
41
+ # <patternFill patternType="solid">
42
+ # <fgColor theme="0" tint="-0.249977111117893" />
43
+ # <bgColor indexed="64" />
44
+ # </patternFill>
45
+ # </fill>
46
+ # <fill>
47
+ # <patternFill patternType="solid">
48
+ # <fgColor theme="0" tint="-0.249977111117893" />
49
+ # <bgColor indexed="31" />
50
+ # </patternFill>
51
+ # </fill>
52
+ # <fill>
53
+ # <patternFill patternType="solid">
54
+ # <fgColor theme="0" tint="-4.9989318521683403E-2" />
55
+ # <bgColor indexed="64" />
56
+ # </patternFill>
57
+ # </fill>
58
+ # <fill>
59
+ # <patternFill patternType="solid">
60
+ # <fgColor rgb="FFFFFF00" />
61
+ # <bgColor indexed="64" />
62
+ # </patternFill>
63
+ # </fill>
64
+ # <fill>
65
+ # <patternFill patternType="solid">
66
+ # <fgColor theme="0" tint="-0.24994659260841701" />
67
+ # <bgColor indexed="64" />
68
+ # </patternFill>
69
+ # </fill>
70
+ # <fill>
71
+ # <patternFill patternType="solid">
72
+ # <fgColor rgb="FFFFCC99" />
73
+ # <bgColor indexed="64" />
74
+ # </patternFill>
75
+ # </fill>
76
+ # </fills>
@@ -22,3 +22,21 @@ class OOXL
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ # <fonts count="3">
27
+ # <font>
28
+ # <sz val="10" />
29
+ # <name val="Arial" />
30
+ # </font>
31
+ # <font>
32
+ # <sz val="10" />
33
+ # <name val="Arial" />
34
+ # <family val="2" />
35
+ # </font>
36
+ # <font>
37
+ # <b />
38
+ # <sz val="9" />
39
+ # <name val="Arial" />
40
+ # <family val="2" />
41
+ # </font>
42
+ # </fonts>
@@ -11,3 +11,22 @@ class OOXL
11
11
  end
12
12
  end
13
13
  end
14
+
15
+ # <numFmts count="16">
16
+ # <numFmt numFmtId="172" formatCode="000\ 00000\ 00000\ 0" />
17
+ # <numFmt numFmtId="173" formatCode="00000.0000" />
18
+ # <numFmt numFmtId="174" formatCode="00.0" />
19
+ # <numFmt numFmtId="175" formatCode="0000.0" />
20
+ # <numFmt numFmtId="176" formatCode="000000000" />
21
+ # <numFmt numFmtId="177" formatCode="0000" />
22
+ # <numFmt numFmtId="178" formatCode="0000000" />
23
+ # <numFmt numFmtId="179" formatCode="mm/dd/yy" />
24
+ # <numFmt numFmtId="180" formatCode="000000" />
25
+ # <numFmt numFmtId="181" formatCode="00" />
26
+ # <numFmt numFmtId="182" formatCode="0.000" />
27
+ # <numFmt numFmtId="183" formatCode="0.0" />
28
+ # <numFmt numFmtId="184" formatCode="000\ 00000\ 00000" />
29
+ # <numFmt numFmtId="185" formatCode="000000\ 000" />
30
+ # <numFmt numFmtId="186" formatCode="00000" />
31
+ # <numFmt numFmtId="187" formatCode="[$-F800]dddd\,\ mmmm\ dd\,\ yyyy" />
32
+ # </numFmts>
data/lib/ooxl.rb CHANGED
@@ -7,6 +7,7 @@ require 'zip'
7
7
  require "ooxl/version"
8
8
 
9
9
  # library
10
+ require "ooxl/list_helper"
10
11
  require "ooxl/ooxl"
11
12
  require "ooxl/util"
12
13
  require "ooxl/xl_objects/workbook"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooxl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.4.2
4
+ version: 0.0.1.4.4
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-09-14 00:00:00.000000000 Z
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -116,6 +116,7 @@ files:
116
116
  - bin/console
117
117
  - bin/setup
118
118
  - lib/ooxl.rb
119
+ - lib/ooxl/list_helper.rb
119
120
  - lib/ooxl/ooxl.rb
120
121
  - lib/ooxl/util.rb
121
122
  - lib/ooxl/version.rb