simple_xlsx_reader 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ ### 0.9.1
2
+
3
+ * Fixed an important parse bug that ignored empty 'Generic' cells
4
+
5
+ ### 0.9.0
6
+
7
+ * Initial release. 0.9 version number is meant to reflect the near-stable
8
+ public api, yet still prerelease status of the project.
data/README.md CHANGED
@@ -91,6 +91,10 @@ Or install it yourself as:
91
91
 
92
92
  $ gem install simple_xlsx_reader
93
93
 
94
+ ## Versioning
95
+
96
+ This project follows [semantic versioning 1.0](http://semver.org/spec/v1.0.0.html)
97
+
94
98
  ## Contributing
95
99
 
96
100
  1. Fork it
@@ -109,23 +109,35 @@ module SimpleXlsxReader
109
109
  def parse_sheet(sheet_name, xsheet)
110
110
  sheet = Sheet.new(sheet_name)
111
111
 
112
+ last_column = xsheet.xpath('/xmlns:worksheet/xmlns:dimension').first.
113
+ attributes['ref'].value.match(/:([A-Z]*)[1-9]*/).captures.first
114
+
112
115
  rownum = -1
113
116
  sheet.rows =
114
117
  xsheet.xpath("/xmlns:worksheet/xmlns:sheetData/xmlns:row").map do |xrow|
115
118
  rownum += 1
116
119
 
117
- colnum = -1
118
- xrow.xpath('xmlns:c').map do |xcell|
120
+ colname = nil
121
+ colnum = -1
122
+ cells = []
123
+ while(colname != last_column) do
124
+ colname ? colname.next! : colname = 'A'
119
125
  colnum += 1
120
126
 
127
+ xcell = xrow.xpath(
128
+ %(xmlns:c[@r="#{colname + (rownum + 1).to_s}"])).first
129
+
130
+ # empty 'General' columns might not be in the xml
131
+ next cells << nil if xcell.nil?
132
+
121
133
  type = xcell.attributes['t'] &&
122
134
  xcell.attributes['t'].value
123
135
  # If not the above, attempt to determine from a custom style
124
136
  type ||= xcell.attributes['s'] &&
125
137
  style_types[xcell.attributes['s'].value.to_i]
126
138
 
127
- begin
128
- self.class.cast(xcell.text, type, shared_strings: shared_strings)
139
+ cells << begin
140
+ self.class.cast(xcell.text.strip, type, shared_strings: shared_strings)
129
141
  rescue => e
130
142
  if !SimpleXlsxReader.configuration.catch_cell_load_errors
131
143
  error = CellLoadError.new(
@@ -135,10 +147,12 @@ module SimpleXlsxReader
135
147
  else
136
148
  sheet.load_errors[[rownum, colnum]] = e.message
137
149
 
138
- xcell.text
150
+ xcell.text.strip
139
151
  end
140
152
  end
141
153
  end
154
+
155
+ cells
142
156
  end
143
157
 
144
158
  sheet
@@ -1,3 +1,3 @@
1
1
  module SimpleXlsxReader
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -66,9 +66,10 @@ describe SimpleXlsxReader do
66
66
  xml.sheets = [Nokogiri::XML(
67
67
  <<-XML
68
68
  <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
69
+ <dimension ref="A1:A1" />
69
70
  <sheetData>
70
71
  <row>
71
- <c s='0'>
72
+ <c r='A1' s='0'>
72
73
  <v>14 is a date style; this is not a date</v>
73
74
  </c>
74
75
  </row>
@@ -104,5 +105,46 @@ describe SimpleXlsxReader do
104
105
  sheet.load_errors[[0,0]].must_include 'invalid value for Integer'
105
106
  end
106
107
  end
108
+
109
+ describe 'empty "Generic" cells' do
110
+ let(:xml) do
111
+ SimpleXlsxReader::Document::Xml.new.tap do |xml|
112
+ xml.sheets = [Nokogiri::XML(
113
+ <<-XML
114
+ <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
115
+ <dimension ref="A1:C1" />
116
+ <sheetData>
117
+ <row>
118
+ <c r='A1' s='0'>
119
+ <v>Cell A</v>
120
+ </c>
121
+ <c r='C1' s='0'>
122
+ <v>Cell C</v>
123
+ </c>
124
+ </row>
125
+ </sheetData>
126
+ </worksheet>
127
+ XML
128
+ )]
129
+
130
+ # s='0' above refers to the value of numFmtId at cellXfs index 0,
131
+ # which is in this case 'General' type
132
+ xml.styles = Nokogiri::XML(
133
+ <<-XML
134
+ <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
135
+ <cellXfs count="1">
136
+ <xf numFmtId="0" />
137
+ </cellXfs>
138
+ </styleSheet>
139
+ XML
140
+ )
141
+ end
142
+ end
143
+
144
+ it 'get parsed as nil' do
145
+ described_class.new(xml).parse_sheet('test', xml.sheets.first).
146
+ rows.must_equal [['Cell A', nil, 'Cell C']]
147
+ end
148
+ end
107
149
  end
108
150
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_xlsx_reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
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-01-16 00:00:00.000000000 Z
12
+ date: 2013-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -67,6 +67,7 @@ extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
69
  - .gitignore
70
+ - CHANGELOG.md
70
71
  - Gemfile
71
72
  - LICENSE.txt
72
73
  - README.md