oxcelix 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +2 -0
- data/CHANGES +11 -0
- data/lib/oxcelix.rb +1 -1
- data/lib/oxcelix/cell.rb +1 -0
- data/lib/oxcelix/cellhelper.rb +4 -2
- data/lib/oxcelix/sax/comments.rb +4 -0
- data/lib/oxcelix/sax/sharedstrings.rb +2 -0
- data/lib/oxcelix/sheet.rb +19 -7
- data/lib/oxcelix/workbook.rb +7 -8
- data/oxcelix.gemspec +3 -3
- metadata +4 -2
data/.yardopts
ADDED
data/CHANGES
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
|
2
|
+
08/10: The sheet class now inherits Matrix. Sheet can return a cell based on its excel name. Sheet::data is obsolete - deleted. Moved r, v, s to the Cellvalues module - they are not needed elsewhere but the Cell class. Documentation changes. .yardopts file added.
|
3
|
+
slight documentation changes, yard options added to (protected and private methods docs are now readable)
|
4
|
+
|
5
|
+
07/10: Changed gem version
|
6
|
+
Removed sharedstrings and sheetbase properties as they were useless. Docs updated with the change.
|
7
|
+
Update oxcelix.gemspec
|
8
|
+
Raised visibility in rdoc, so that all method documentation gets readable.
|
9
|
+
Update workbook.rb
|
10
|
+
replaced Ox::load_file with IO.read + Ox::load in workbook, as apparently workbook.xml could not be loaded under windows using that method
|
11
|
+
Minor typos corrected, added gemspec
|
data/lib/oxcelix.rb
CHANGED
@@ -13,7 +13,7 @@ require 'oxcelix/sax/xlsheet'
|
|
13
13
|
|
14
14
|
class String
|
15
15
|
# Returns true if the given String represents a numeric value
|
16
|
-
# @return [Bool]
|
16
|
+
# @return [Bool] true if the string represents a numeric value, false if it doesn't.
|
17
17
|
def numeric?
|
18
18
|
Float(self) != nil rescue false
|
19
19
|
end
|
data/lib/oxcelix/cell.rb
CHANGED
data/lib/oxcelix/cellhelper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Oxcelix
|
3
3
|
# The Cellhelper module defines some methods useful to manipulate Cell objects
|
4
|
-
module
|
4
|
+
module Cellvalues
|
5
5
|
# Set the excel cell name (eg: 'A2')
|
6
6
|
# @param [String] val Excel cell address name
|
7
7
|
def r(val); @xlcoords = val; end;
|
@@ -11,7 +11,9 @@ module Oxcelix
|
|
11
11
|
def v(val); @value = val; end;
|
12
12
|
# Set cell style (number format and style)
|
13
13
|
def s(val); @style = val; end;
|
14
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
module Cellhelper
|
15
17
|
# When called without parameters, returns the x coordinate of the calling cell object based on the value of #@xlcoords
|
16
18
|
# If a parameter is given, #x will return the x coordinate corresponding to the parameter
|
17
19
|
# @example find x coordinate (column number) of a cell
|
data/lib/oxcelix/sax/comments.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Oxcelix
|
2
2
|
# The Comments class is a parser which builds an array of comments
|
3
3
|
class Comments < ::Ox::Sax
|
4
|
+
# @!attribute [rw] commarray
|
5
|
+
# @return [Array] the array of all comments of a given sheet
|
6
|
+
# @!attribute [rw] comment
|
7
|
+
# @return [Hash] a hash representing a comment
|
4
8
|
attr_accessor :commarray, :comment
|
5
9
|
def initialize
|
6
10
|
@commarray=[]
|
@@ -2,6 +2,8 @@ module Oxcelix
|
|
2
2
|
# Ox based SAX parser which pushes shared strings (taken from the sharedString.xml file) to an array
|
3
3
|
# These strings will replace the references in the cells (interpolation).
|
4
4
|
class Sharedstrings < ::Ox::Sax
|
5
|
+
# @!attribute [rw] stringarray
|
6
|
+
# @return [Array] the array of all the strings found in sharedStrings.xml
|
5
7
|
attr_accessor :stringarray
|
6
8
|
def initialize
|
7
9
|
@stringarray=[]
|
data/lib/oxcelix/sheet.rb
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
|
2
2
|
module Oxcelix
|
3
3
|
# The Sheet class represents an excel sheet.
|
4
|
+
class Sheet < Matrix
|
5
|
+
include Cellhelper
|
4
6
|
# @!attribute [rw] name
|
5
7
|
# @return [String] Sheet name
|
6
8
|
# @!attribute [rw] sheetId
|
7
9
|
# @return [String] returns the sheetId SheetML internal attribute
|
8
10
|
# @!attribute [rw] relationId
|
9
|
-
# @return [String]
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
# @return [String] Internal reference key. relationID is used internally by Excel 2010 to e.g. build up the relationship between worksheets and comments
|
12
|
+
attr_accessor :name, :sheetId, :relationId
|
13
|
+
|
14
|
+
# The [] method overrides the standard Matrix::[]. It will now accept Excel-style cell coordinates.
|
15
|
+
# @param [String] i
|
16
|
+
# @return [Cell] the object denoted with the Excel column-row name.
|
17
|
+
# @example Select a cell in a sheet
|
18
|
+
# w = Oxcelix::Workbook.new('Example.xlsx')
|
19
|
+
# w.sheets[0][3,1] #=> #<Oxcelix::Cell:0x00000001e00fa0 @xlcoords="B4", @style="0", @type="n", @value="3">
|
20
|
+
# w.sheets[0]['B4'] #=> #<Oxcelix::Cell:0x00000001e00fa0 @xlcoords="B4", @style="0", @type="n", @value="3">
|
21
|
+
def [](i, *j)
|
22
|
+
if i.is_a? String
|
23
|
+
super(y(i),x(i))
|
24
|
+
else
|
25
|
+
super(i,j[0])
|
26
|
+
end
|
27
|
+
end
|
16
28
|
end
|
17
29
|
end
|
data/lib/oxcelix/workbook.rb
CHANGED
@@ -15,13 +15,13 @@ module Oxcelix
|
|
15
15
|
# The Workbook class will open the excel file, and convert it to a collection of
|
16
16
|
# Matrix objects
|
17
17
|
# @!attribute [rw] sheets
|
18
|
-
# @return [Array]
|
18
|
+
# @return [Array] a collection of {Sheet} objects
|
19
19
|
class Workbook
|
20
20
|
include Cellhelper
|
21
21
|
include Workbookhelper
|
22
22
|
attr_accessor :sheets
|
23
23
|
##
|
24
|
-
# Create a new Workbook object.
|
24
|
+
# Create a new {Workbook} object.
|
25
25
|
#
|
26
26
|
# filename is the name of the Excel 2007/2010 file to be opened (xlsx)
|
27
27
|
#
|
@@ -176,11 +176,12 @@ module Oxcelix
|
|
176
176
|
#
|
177
177
|
# The matrix will replace the array of cells in the actual sheet.
|
178
178
|
# @param [Bool ] copymerge
|
179
|
-
# @return [Matrix] a Matrix that stores the cell values, and, depending on the copymerge parameter, will copy the merged value
|
179
|
+
# @return [Matrix] a Matrix object that stores the cell values, and, depending on the copymerge parameter, will copy the merged value
|
180
180
|
# into every merged cell
|
181
181
|
def matrixto(copymerge)
|
182
182
|
@sheets.each_with_index do |sheet, i|
|
183
|
-
m=Matrix.build(sheet[:cells].last.y+1, sheet[:cells].last.x+1) {nil}
|
183
|
+
#m=Matrix.build(sheet[:cells].last.y+1, sheet[:cells].last.x+1) {nil}
|
184
|
+
m=Sheet.build(sheet[:cells].last.y+1, sheet[:cells].last.x+1) {nil}
|
184
185
|
sheet[:cells].each do |c|
|
185
186
|
m[c.y, c.x]=c
|
186
187
|
end
|
@@ -207,10 +208,8 @@ module Oxcelix
|
|
207
208
|
end
|
208
209
|
end
|
209
210
|
end
|
210
|
-
|
211
|
-
|
212
|
-
s.data=m
|
213
|
-
@sheets[i]=s
|
211
|
+
m.name=@sheets[i][:name]; m.sheetId=@sheets[i][:sheetId]; m.relationId=@sheets[i][:relationId]
|
212
|
+
@sheets[i]=m
|
214
213
|
end
|
215
214
|
end
|
216
215
|
end
|
data/oxcelix.gemspec
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'rake'
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'oxcelix'
|
6
|
-
s.version = '0.
|
7
|
-
s.date = '2013-10-
|
6
|
+
s.version = '0.2.0'
|
7
|
+
s.date = '2013-10-08'
|
8
8
|
s.summary = 'A fast Excel 2007/2010 file parser'
|
9
9
|
s.description = 'A fast .xlsx file parser that returns a collection of Matrix objects'
|
10
10
|
s.authors = 'Giovanni Biczo'
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
s.files = FileList["LICENSE", "README.rdoc", "README.md",
|
15
15
|
"lib/*", "lib/oxcelix/*", "lib/oxcelix/sax/*",
|
16
|
-
"oxcelix.gemspec", "spec/*"].to_a
|
16
|
+
"oxcelix.gemspec", "spec/*", ".yardopts", "CHANGES"].to_a
|
17
17
|
s.license = 'MIT'
|
18
18
|
|
19
19
|
s.add_runtime_dependency "ox", [">= 2.0.6"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oxcelix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ox
|
@@ -68,6 +68,8 @@ files:
|
|
68
68
|
- spec/cell_spec.rb
|
69
69
|
- spec/matrix_spec.rb
|
70
70
|
- spec/string_spec.rb
|
71
|
+
- .yardopts
|
72
|
+
- CHANGES
|
71
73
|
homepage: http://github.com/gbiczo/oxcelix
|
72
74
|
licenses:
|
73
75
|
- MIT
|