rubyXL 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.5
1
+ 1.2.6
@@ -29,7 +29,8 @@ module RubyXL
29
29
  if !@value.is_a?(String)
30
30
  if @workbook.num_fmts
31
31
  num_fmt_id = xf_id()[:numFmtId]
32
- num_fmt = @workbook.num_fmts[:numFmt].select { |f| f[:attributes][:numFmtId] == num_fmt_id }[0].andand[:attributes].andand[:formatCode]
32
+ tmp_num_fmt = @workbook.num_fmts[:numFmt].select { |f| f[:attributes][:numFmtId] == num_fmt_id }[0]
33
+ num_fmt = (tmp && tmp[:attributes] && tmp[:attributes][:formatCode]) ? tmp[:attributes][:formatCode] : nil
33
34
  if num_fmt && workbook.date_num_fmt?(num_fmt)
34
35
  return true
35
36
  end
@@ -40,9 +40,13 @@ module RubyXL
40
40
 
41
41
  # data_only allows only the sheet data to be parsed, so as to speed up parsing
42
42
  # However, using this option will result in date-formatted cells being interpreted as numbers
43
- def Parser.parse(file_path, data_only=false)
44
- @data_only = data_only
45
- files = Parser.decompress(file_path)
43
+ def Parser.parse(file_path, opts = {})
44
+
45
+ # options handling
46
+ @data_only = opts.is_a?(TrueClass)||!!opts[:data_only]
47
+ skip_filename_check = !!opts[:skip_filename_check]
48
+
49
+ files = Parser.decompress(file_path, skip_filename_check)
46
50
  wb = Parser.fill_workbook(file_path, files)
47
51
 
48
52
  if(files['sharedString'] != nil)
@@ -213,7 +217,7 @@ module RubyXL
213
217
  ##end legacy drawing
214
218
  end
215
219
 
216
-
220
+
217
221
  row_data = files[j].xpath('/xmlns:worksheet/xmlns:sheetData/xmlns:row[xmlns:c[xmlns:v]]',namespaces)
218
222
  row_data.each do |row|
219
223
  unless @data_only
@@ -261,7 +265,7 @@ module RubyXL
261
265
  cell_data = v_element_content
262
266
  else# (value.css('v').to_s != "") && (value.css('v').children.to_s != "") #is number
263
267
  data_type = ''
264
- if(v_element_content =~ /\./) #is float
268
+ if(v_element_content =~ /\./ or v_element_content =~ /\d+e\-?\d+/i) #is float
265
269
  cell_data = Float(v_element_content)
266
270
  else
267
271
  cell_data = Integer(v_element_content)
@@ -295,12 +299,16 @@ module RubyXL
295
299
  end
296
300
  end
297
301
 
298
- def Parser.decompress(file_path)
302
+ def Parser.decompress(file_path, skip_filename_check = false)
299
303
  #ensures it is an xlsx/xlsm file
300
304
  if(file_path =~ /(.+)\.xls(x|m)/)
301
305
  dir_path = $1.to_s
302
306
  else
303
- raise 'Not .xlsx or .xlsm excel file'
307
+ if skip_filename_check
308
+ dir_path = file_path
309
+ else
310
+ raise 'Not .xlsx or .xlsm excel file'
311
+ end
304
312
  end
305
313
 
306
314
  dir_path = File.join(File.dirname(dir_path), make_safe_name(Time.now.to_s))
@@ -345,7 +353,7 @@ module RubyXL
345
353
 
346
354
  if File.directory?(File.join(dir_path,'xl','drawings'))
347
355
  files['drawings'] = {}
348
- drawings_path = File.join(dir_path,'xl','drawings')
356
+ drawings_path = File.join(dir_path,'xl','drawings','_rels')
349
357
 
350
358
  dir = Dir.new(drawings_path).entries.reject {|f| [".", "..", ".DS_Store"].include? f}
351
359
  dir.each_with_index do |draw,i|
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubyXL}
8
- s.version = "1.2.5"
8
+ s.version = "1.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Vivek Bhagwat"]
12
- s.date = %q{2012-01-25}
12
+ s.date = %q{2012-04-10}
13
13
  s.description = %q{rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx/.xlsm) Documents}
14
14
  s.email = %q{bhagwat.vivek@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -32,8 +32,18 @@ describe RubyXL::Parser do
32
32
  lambda {@workbook2 = RubyXL::Parser.parse(@time_str+".xls")}.should raise_error
33
33
  end
34
34
 
35
+ it 'should not cause an error if an xlsx or xlsm workbook is not passed but the skip_filename_check option is used' do
36
+ filename = @time_str
37
+ FileUtils.cp(@file, filename)
38
+
39
+ lambda {@workbook2 = RubyXL::Parser.parse(filename)}.should raise_error
40
+ lambda {@workbook2 = RubyXL::Parser.parse(filename, :skip_filename_check => true)}.should_not raise_error
41
+
42
+ File.delete(filename)
43
+ end
44
+
35
45
  it 'should only read the data and not any of the styles (for the sake of speed) when passed true' do
36
- @workbook2 = RubyXL::Parser.parse(@file, true)
46
+ @workbook2 = RubyXL::Parser.parse(@file, :data_only => true)
37
47
 
38
48
  @workbook2.worksheets.size.should == @workbook.worksheets.size
39
49
  @workbook2[0].sheet_data.should == @workbook[0].sheet_data
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyXL
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 5
9
+ - 6
10
10
  segments_generated: true
11
- version: 1.2.5
11
+ version: 1.2.6
12
12
  platform: ruby
13
13
  authors:
14
14
  - Vivek Bhagwat
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-01-25 00:00:00 -05:00
19
+ date: 2012-04-10 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency