saxlsx 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54925b1ff0a1cf772d1b5c26c1eee0c6f2d777ba
4
- data.tar.gz: 1bbb66a26a5f095b0d11338d91da3024a93258d0
3
+ metadata.gz: f695e5e0a2470321d739c99840624c0e0e52808b
4
+ data.tar.gz: eb92f3e6bec02f95a642274511dc4d4b1abf052a
5
5
  SHA512:
6
- metadata.gz: 27af434e8a16a6a779ed938a68c1b0e0deea8a1c80a272f99b96c17cf3923fb15567c378fef3e3eeb3826726ae2cb21f22d19b08e00d2007713654bb955f8cef
7
- data.tar.gz: fe50048d93f025e557f5aba24dc107865f8438a8d840197e8a55cdc83e52211db6e5f6e29eeb9cc11de3b01ce11af5941d3e63b863d23ce9a4dd90f94703678e
6
+ metadata.gz: 484bab7c1138454a5a6bcd6cd60e021bb0b2fc58bac5489af6e369b6733ca8804f1c53dce1d95a3c12693b86355c032cdcf73ece0b04167c36a82fc3b24a2845
7
+ data.tar.gz: 26ba631f53a1d194ff8dbc7c2baedfb366387d66ebc68940f49bb4ca7acc8adf0569c3be6114d710d6850b5882b3a4ac829114063e2a5c52f7ff03d8593e2109
@@ -16,21 +16,7 @@ module Saxlsx
16
16
  end
17
17
 
18
18
  def count
19
- unless defined?(@count)
20
- @count = 0
21
- begin
22
- @sheet.each_line('>') do |line|
23
- matches = line.match(/<dimension ref="[^:]+:[A-Z]*(\d+)"/)
24
- if matches
25
- @count = matches[1].to_i
26
- break if @count
27
- end
28
- end
29
- ensure
30
- @sheet.rewind
31
- end
32
- end
33
- @count
19
+ @count ||= RowsCollectionCountParser.count @sheet
34
20
  end
35
21
 
36
22
  alias :size :count
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+ module Saxlsx
3
+ class RowsCollectionCountParser < Ox::Sax
4
+ def self.count(data, &block)
5
+ parser = new
6
+ catch :abort do
7
+ SaxParser.parse parser, data
8
+ end
9
+ parser.count
10
+ end
11
+
12
+ attr_reader :count
13
+
14
+ def initialize
15
+ @count = 0
16
+ end
17
+
18
+ def start_element(name)
19
+ @current_element = name
20
+ if name == :row
21
+ @count += 1
22
+ end
23
+ end
24
+
25
+ def attr(name, value)
26
+ if @current_element == :dimension
27
+ if name == :ref && value
28
+ matches = value.match(/[^:]+:[A-Z]*(\d+)/)
29
+ if matches
30
+ @count = matches[1].to_i
31
+ throw :abort
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -33,7 +33,7 @@ module Saxlsx
33
33
  if custom_num_fmt_code
34
34
  @block.call custom_num_fmt_code
35
35
  else
36
- @block.call @num_fmt_id
36
+ @block.call @num_fmt_id.to_i
37
37
  end
38
38
  end
39
39
  when :numFmt
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Saxlsx
3
- VERSION = '1.7.1'
3
+ VERSION = '1.8.0'
4
4
  end
Binary file
@@ -93,6 +93,19 @@ describe Sheet do
93
93
  end
94
94
  end
95
95
 
96
+ it 'Handle missing fonts and dimension tags' do
97
+ filename = "#{File.dirname(__FILE__)}/data/SpecSloppy.xlsx"
98
+
99
+ Workbook.open filename do |w|
100
+ w.sheets[0].rows.count.should eq 85
101
+ headers = w.sheets[0].rows.first
102
+ headers.count.should eq 52
103
+ headers.each do |str|
104
+ str.should eq "X"
105
+ end
106
+ end
107
+ end
108
+
96
109
  context 'with 1904 date system' do
97
110
  let(:filename) { "#{File.dirname(__FILE__)}/data/Spec1904.xlsx" }
98
111
 
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.7.1
4
+ version: 1.8.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-08-28 00:00:00.000000000 Z
11
+ date: 2018-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -114,6 +114,7 @@ files:
114
114
  - lib/saxlsx/column_name_generator.rb
115
115
  - lib/saxlsx/file_system.rb
116
116
  - lib/saxlsx/rows_collection.rb
117
+ - lib/saxlsx/rows_collection_count_parser.rb
117
118
  - lib/saxlsx/rows_collection_parser.rb
118
119
  - lib/saxlsx/sax_parser.rb
119
120
  - lib/saxlsx/shared_string_collection.rb
@@ -132,6 +133,7 @@ files:
132
133
  - spec/data/Spec1904.xlsx
133
134
  - spec/data/SpecInlineStrings.xlsx
134
135
  - spec/data/SpecNumberFormat.xlsx
136
+ - spec/data/SpecSloppy.xlsx
135
137
  - spec/sheet_spec.rb
136
138
  - spec/spec_helper.rb
137
139
  - spec/workbook_spec.rb
@@ -166,6 +168,7 @@ test_files:
166
168
  - spec/data/Spec1904.xlsx
167
169
  - spec/data/SpecInlineStrings.xlsx
168
170
  - spec/data/SpecNumberFormat.xlsx
171
+ - spec/data/SpecSloppy.xlsx
169
172
  - spec/sheet_spec.rb
170
173
  - spec/spec_helper.rb
171
174
  - spec/workbook_spec.rb