ooxl 0.0.1.3 → 0.0.1.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 +4 -4
- data/README.md +40 -34
- data/lib/ooxl/ooxl.rb +11 -1
- data/lib/ooxl/version.rb +1 -1
- data/lib/ooxl/xl_objects/relationships.rb +38 -0
- data/lib/ooxl.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c035a6d25dad9b2fc7ce50c39416b21f02fdb37
|
4
|
+
data.tar.gz: d2a0e05e803f3342517046954320a47811ded2ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a41f60dc9727d85afa0f5962d1767b0bb4085590f30a5e27239e736b8e43c81a70cae362f9f3aeea2c4e11b400e6f97c3d629a818f2bc8783f7d934e66ed9fb7
|
7
|
+
data.tar.gz: 984607ce44b44d6ab6fb8d38f56a93de5225d4f09763834408081fc754be657bf23b481f494b744005ccd082759760fca79c04a206a43e55f42b1dd093c343b8
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# OOXL
|
2
2
|
|
3
3
|
TODO: Description
|
4
4
|
|
@@ -7,7 +7,7 @@ TODO: Description
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem '
|
10
|
+
gem 'ooxl'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -16,85 +16,91 @@ And then execute:
|
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
$ gem install
|
19
|
+
$ gem install ooxl
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
###
|
23
|
+
### reading an excel spreadsheet:
|
24
24
|
```
|
25
|
-
|
25
|
+
ooxl = OOXL.new('example.xlsx')
|
26
|
+
|
27
|
+
or
|
28
|
+
|
29
|
+
ooxl = OOXL.open('example.xlsx')
|
26
30
|
```
|
27
31
|
|
28
32
|
### Fetching all sheets:
|
29
33
|
```
|
30
|
-
|
34
|
+
ooxl.sheets # ['Test Sheet 1', 'Test Sheet 2']
|
31
35
|
```
|
32
36
|
|
33
37
|
### Accessing Rows and Cells
|
34
38
|
```
|
35
|
-
sheet =
|
39
|
+
sheet = ooxl.sheet('Test Sheet 1')
|
36
40
|
|
37
41
|
# Rows
|
38
|
-
sheet[0] # Access the first row
|
39
|
-
sheet
|
42
|
+
sheet.rows[0] # Access the first row
|
43
|
+
sheet[0] # short version
|
40
44
|
|
41
45
|
# Cells
|
42
|
-
sheet[0].cells #
|
43
|
-
sheet
|
46
|
+
sheet.rows[0].cells # access the cells of the first row
|
47
|
+
sheet[0].cells # short version
|
44
48
|
|
45
|
-
sheet[0][0] # Access the first cell of the row
|
46
|
-
sheet
|
49
|
+
sheet.rows[0].cells[0] # Access the first cell of the row
|
50
|
+
sheet[0][0] # short version
|
47
51
|
|
48
|
-
sheet[0][0].value # Access cell value
|
49
|
-
sheet
|
52
|
+
sheet.rows[0].cells[0].value # Access cell value
|
53
|
+
sheet[0][0].value# short version
|
50
54
|
|
51
|
-
|
55
|
+
# Fetch cell value using the short versions
|
56
|
+
ooxl['Test Sheet 1'][0][0].value
|
52
57
|
```
|
53
58
|
|
54
|
-
###
|
59
|
+
### Iteration
|
55
60
|
```
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
61
|
+
ooxl.sheet('Test Sheet 1').each do |row|
|
62
|
+
row.each_with_index do |cell, cell_index|
|
63
|
+
# do something here..
|
64
|
+
end
|
60
65
|
end
|
61
66
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
ooxl.each do |sheet|
|
68
|
+
sheet.each do |row|
|
69
|
+
row.each do |cell|
|
70
|
+
# do something here...
|
71
|
+
end
|
72
|
+
end
|
66
73
|
end
|
67
|
-
|
68
74
|
```
|
69
75
|
|
70
76
|
### Fetching Columns
|
71
77
|
```
|
72
78
|
# Fetch all columns
|
73
|
-
|
79
|
+
ooxl.sheet('Test Sheet 1').columns
|
74
80
|
|
75
81
|
# Checking if the column is hidden
|
76
|
-
|
77
|
-
|
82
|
+
ooxl.sheet('Test Sheet 1').column(1).hidden? # column index
|
83
|
+
ooxl.sheet('Test Sheet 1').column('A').hidden? # column letter
|
78
84
|
```
|
79
85
|
|
80
86
|
### Fetching Styles
|
81
87
|
```
|
82
88
|
# Font
|
83
|
-
font_object =
|
89
|
+
font_object = ooxl.sheet('Test Sheet 1').font('A1')
|
84
90
|
font_object.bold? # false
|
85
91
|
font_object.name # Arial
|
86
92
|
font_object.rgb_color # FFE10000
|
87
93
|
font_object.size # 8
|
88
94
|
|
89
95
|
# Cell Fill
|
90
|
-
fill_object =
|
96
|
+
fill_object = ooxl.sheet('Test Sheet 1').fill('A1')
|
91
97
|
fill_object.bg_color # FFE10000
|
92
98
|
fill_object.fg_color # FFE10000
|
93
99
|
```
|
94
100
|
### Fetching Data from named/cell range
|
95
101
|
```
|
96
102
|
# named range
|
97
|
-
|
103
|
+
ooxl.named_range('my_named_range') # ['value' 'from', 'range']
|
98
104
|
|
99
105
|
# cell range
|
100
106
|
ooxml['Lists'!$A$1:$A$6] # ['1','2','3','4','5','6']
|
@@ -112,7 +118,7 @@ ooxml['Lists!A1:B2'] # [['1', '2'], ['2','3']]
|
|
112
118
|
### Fetching Data Validation
|
113
119
|
```
|
114
120
|
# All Validations
|
115
|
-
data_validations =
|
121
|
+
data_validations = ooxl.sheet('Test Sheet 1').data_validations
|
116
122
|
|
117
123
|
# Specific validation for cell
|
118
124
|
data_validation = ooxml.sheet('Input Sheet').data_validation('D4')
|
@@ -131,4 +137,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
131
137
|
|
132
138
|
## Contributing
|
133
139
|
|
134
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/halcjames/
|
140
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/halcjames/ooxl.
|
data/lib/ooxl/ooxl.rb
CHANGED
@@ -5,6 +5,7 @@ class OOXL
|
|
5
5
|
@sheets = {}
|
6
6
|
@styles = []
|
7
7
|
@comments = {}
|
8
|
+
@relationships = {}
|
8
9
|
parse_spreadsheet_contents(spreadsheet_filepath)
|
9
10
|
end
|
10
11
|
|
@@ -29,7 +30,7 @@ class OOXL
|
|
29
30
|
|
30
31
|
# shared variables
|
31
32
|
sheet.name = sheet_name
|
32
|
-
sheet.comments =
|
33
|
+
sheet.comments = fetch_comments(sheet_index)
|
33
34
|
sheet.styles = @styles
|
34
35
|
sheet.defined_names = @workbook.defined_names
|
35
36
|
sheet
|
@@ -61,6 +62,12 @@ class OOXL
|
|
61
62
|
end
|
62
63
|
alias_method :list_values, :load_list_values
|
63
64
|
|
65
|
+
def fetch_comments(sheet_index)
|
66
|
+
final_sheet_index = sheet_index+1
|
67
|
+
relationship = @relationships[final_sheet_index.to_s]
|
68
|
+
@comments[relationship.comment_id] if relationship.present?
|
69
|
+
end
|
70
|
+
|
64
71
|
def parse_spreadsheet_contents(spreadsheet)
|
65
72
|
shared_strings = []
|
66
73
|
Zip::File.open(spreadsheet) do |spreadsheet_zip|
|
@@ -80,6 +87,9 @@ class OOXL
|
|
80
87
|
end
|
81
88
|
when "xl/workbook.xml"
|
82
89
|
@workbook = OOXL::Workbook.load_from_stream(entry.get_input_stream.read)
|
90
|
+
when /xl\/worksheets\/_rels\/sheet\d+\.xml\.rels/
|
91
|
+
sheet_id = entry.name.scan(/sheet(\d+)/).flatten.first
|
92
|
+
@relationships[sheet_id] = Relationships.new(entry.get_input_stream.read)
|
83
93
|
else
|
84
94
|
# unsupported for now..
|
85
95
|
end
|
data/lib/ooxl/version.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
class OOXL
|
2
|
+
class Relationships
|
3
|
+
SUPPORTED_TYPES = ['http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments']
|
4
|
+
def initialize(relationships_node)
|
5
|
+
@types = {}
|
6
|
+
parse_relationships(relationships_node)
|
7
|
+
end
|
8
|
+
|
9
|
+
def comment_id
|
10
|
+
@types['comments']
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def parse_relationships(relationships_node)
|
15
|
+
relationships_node = Nokogiri.XML(relationships_node).remove_namespaces!
|
16
|
+
relationships_node.xpath('//Relationship').each do |relationship_node|
|
17
|
+
relationship_type = relationship_node.attributes["Type"].value
|
18
|
+
target = relationship_node.attributes["Target"].value
|
19
|
+
if supported_type?(relationship_type)
|
20
|
+
@types[extract_type(relationship_type)] = extract_file_reference(target)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def supported_type?(type)
|
26
|
+
SUPPORTED_TYPES.include?(type)
|
27
|
+
end
|
28
|
+
|
29
|
+
def extract_type(type)
|
30
|
+
type.split('/').last
|
31
|
+
end
|
32
|
+
|
33
|
+
def extract_file_reference(file)
|
34
|
+
file.scan(/(\d+)\.[\w]/).flatten.first
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/ooxl.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ooxl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Mones
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/ooxl/xl_objects/cell.rb
|
123
123
|
- lib/ooxl/xl_objects/column.rb
|
124
124
|
- lib/ooxl/xl_objects/comments.rb
|
125
|
+
- lib/ooxl/xl_objects/relationships.rb
|
125
126
|
- lib/ooxl/xl_objects/row.rb
|
126
127
|
- lib/ooxl/xl_objects/sheet.rb
|
127
128
|
- lib/ooxl/xl_objects/sheet/data_validation.rb
|
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
152
|
version: '0'
|
152
153
|
requirements: []
|
153
154
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.4
|
155
|
+
rubygems_version: 2.6.4
|
155
156
|
signing_key:
|
156
157
|
specification_version: 4
|
157
158
|
summary: OOXL Excel - Parse Excel Spreadsheets (xlsx, xlsm).
|