saxlsx 1.5.0 → 1.6.0
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/lib/saxlsx/rows_collection_parser.rb +9 -5
- data/lib/saxlsx/version.rb +1 -1
- data/lib/saxlsx/workbook.rb +5 -3
- data/spec/data/SpecNumberFormat.xlsx +0 -0
- data/spec/sheet_spec.rb +30 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 912aea753226e55b3b97c74c094e36fff1a703b3
|
4
|
+
data.tar.gz: 71b3a09c85b6fbcb8dc5da74dfcb4134d4eb3ba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee4a4b76abdf8d4d797a1704c892cd9359b2b2a646ac38267feeba182d7f349b7016c50788e0382ef9552cc767f2b3356ef5adbf462cc761fc44d24ad164b410
|
7
|
+
data.tar.gz: 1cd5883650144d961e7ff726af1900d5ca037f4c0a9d5efd2aeccdcf9312145ee108c21a6b35e3be8ccde8d942b2b578ed5e0be1c75fb077c8798c6ed947cbf6
|
@@ -14,8 +14,8 @@ module Saxlsx
|
|
14
14
|
9 => :percentage, # 0%
|
15
15
|
10 => :percentage, # 0.00%
|
16
16
|
11 => :bignum, # 0.00E+00
|
17
|
-
12 => :
|
18
|
-
13 => :
|
17
|
+
12 => :rational, # # ?/?
|
18
|
+
13 => :rational, # # ??/??
|
19
19
|
14 => :date, # mm-dd-yy
|
20
20
|
15 => :date, # d-mmm-yy
|
21
21
|
16 => :date, # d-mmm
|
@@ -42,6 +42,7 @@ module Saxlsx
|
|
42
42
|
|
43
43
|
def initialize(workbook, &block)
|
44
44
|
@base_date = workbook.base_date
|
45
|
+
@auto_format = workbook.auto_format
|
45
46
|
@shared_strings = workbook.shared_strings
|
46
47
|
@number_formats = workbook.number_formats
|
47
48
|
@block = block
|
@@ -109,17 +110,20 @@ module Saxlsx
|
|
109
110
|
date = @base_date + Rational((Float(text) * SECONDS_IN_DAY).round, SECONDS_IN_DAY)
|
110
111
|
DateTime.new(date.year, date.month, date.day, date.hour, date.minute, date.second)
|
111
112
|
when :fixnum
|
112
|
-
Integer(text)
|
113
|
+
Integer(text, 10)
|
113
114
|
when :float, :percentage
|
114
115
|
Float(text)
|
116
|
+
when :rational
|
117
|
+
Rational(text)
|
115
118
|
when :bignum
|
116
119
|
Float(text) # raises ArgumentError if text is not a number
|
117
120
|
BigDecimal(text) # doesn't raise ArgumentError
|
118
121
|
else
|
119
122
|
if @current_type == 'n'
|
120
123
|
Float(text)
|
121
|
-
elsif text =~ /\A-?\d+(\.\d+(?:e[+-]\d+)?)?\Z/i
|
122
|
-
|
124
|
+
elsif @auto_format && text =~ /\A-?\d+(\.\d+(?:e[+-]\d+)?)?\Z/i
|
125
|
+
# Auto convert numbers
|
126
|
+
$1 ? Float(text) : Integer(text, 10)
|
123
127
|
else
|
124
128
|
CGI.unescapeHTML(text)
|
125
129
|
end
|
data/lib/saxlsx/version.rb
CHANGED
data/lib/saxlsx/workbook.rb
CHANGED
@@ -4,18 +4,20 @@ module Saxlsx
|
|
4
4
|
DATE_SYSTEM_1904 = DateTime.new(1904, 1, 1)
|
5
5
|
|
6
6
|
attr_accessor :date1904
|
7
|
+
attr_reader :auto_format
|
7
8
|
|
8
|
-
def self.open(
|
9
|
+
def self.open(*args)
|
9
10
|
begin
|
10
|
-
workbook = self.new(
|
11
|
+
workbook = self.new(*args)
|
11
12
|
yield workbook
|
12
13
|
ensure
|
13
14
|
workbook.close
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def initialize(filename)
|
18
|
+
def initialize(filename, auto_format: true)
|
18
19
|
@file_system = FileSystem.new filename
|
20
|
+
@auto_format = auto_format
|
19
21
|
end
|
20
22
|
|
21
23
|
def close
|
Binary file
|
data/spec/sheet_spec.rb
CHANGED
@@ -121,10 +121,12 @@ describe Sheet do
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
context 'with number formats' do
|
124
|
+
context 'with number formats and auto format' do
|
125
125
|
let(:filename) { "#{File.dirname(__FILE__)}/data/SpecNumberFormat.xlsx" }
|
126
126
|
|
127
127
|
[ ["General", "Test"],
|
128
|
+
["General", 123],
|
129
|
+
["General", 123.5],
|
128
130
|
["Fixnum", 123],
|
129
131
|
["Currency", 123.0],
|
130
132
|
["Date", DateTime.new(1970, 1, 1)],
|
@@ -145,4 +147,31 @@ describe Sheet do
|
|
145
147
|
end
|
146
148
|
end
|
147
149
|
end
|
150
|
+
|
151
|
+
context 'with number formats and without auto format' do
|
152
|
+
let(:filename) { "#{File.dirname(__FILE__)}/data/SpecNumberFormat.xlsx" }
|
153
|
+
|
154
|
+
[ ["General", "Test"],
|
155
|
+
["General", "0123"],
|
156
|
+
["General", "0123.50"],
|
157
|
+
["Fixnum", 123],
|
158
|
+
["Currency", 123.0],
|
159
|
+
["Date", DateTime.new(1970, 1, 1)],
|
160
|
+
["Time", DateTime.new(2015, 2, 13, 12, 40, 5)],
|
161
|
+
["Percentage", 0.9999],
|
162
|
+
["Fraction", 0.5],
|
163
|
+
["Scientific", BigDecimal.new('3.4028236692093801E+38')],
|
164
|
+
["Custom", 123.0],
|
165
|
+
].each.with_index do |row, i|
|
166
|
+
name, value = row
|
167
|
+
|
168
|
+
it "should typecast #{name}" do
|
169
|
+
Workbook.open filename, auto_format: false do |w|
|
170
|
+
w.sheets[0].tap do |s|
|
171
|
+
expect(s.rows[i+1]).to eq([name, value, "Test"])
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
148
177
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saxlsx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgars Beigarts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|