rubyXL 1.2.8 → 1.2.9

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.8
1
+ 1.2.9
data/lib/rubyXL/cell.rb CHANGED
@@ -30,9 +30,9 @@ module RubyXL
30
30
 
31
31
  def is_date?
32
32
  if !@value.is_a?(String)
33
- if @workbook.num_fmts
33
+ if @workbook.num_fmts_by_id
34
34
  num_fmt_id = xf_id()[:numFmtId]
35
- tmp_num_fmt = @workbook.num_fmts[:numFmt].select { |f| f[:attributes][:numFmtId] == num_fmt_id }[0]
35
+ tmp_num_fmt = @workbook.num_fmts_by_id[num_fmt_id]
36
36
  num_fmt = (tmp_num_fmt &&tmp_num_fmt[:attributes] && tmp_num_fmt[:attributes][:formatCode]) ? tmp_num_fmt[:attributes][:formatCode] : nil
37
37
  if num_fmt && workbook.date_num_fmt?(num_fmt)
38
38
  return true
data/lib/rubyXL/parser.rb CHANGED
@@ -10,9 +10,7 @@ module RubyXL
10
10
  @@parsed_column_hash ={}
11
11
  # converts cell string (such as "AA1") to matrix indices
12
12
  def Parser.convert_to_index(cell_string)
13
- index = Array.new(2)
14
- index[0]=-1
15
- index[1]=-1
13
+ index = [-1,-1]
16
14
  if(cell_string =~ /^([A-Z]+)(\d+)$/)
17
15
 
18
16
  one = $1
@@ -243,12 +241,19 @@ module RubyXL
243
241
  ##end row styles##
244
242
  end
245
243
 
246
- c_row = row.search('./xmlns:c')
244
+ unless @data_only
245
+ c_row = row.search('./xmlns:c')
246
+ else
247
+ c_row = row.search('./xmlns:c[xmlns:v[text()]]')
248
+ end
247
249
  c_row.each do |value|
250
+ #attributes is from the excel cell(c) and is basically location information and style and type
248
251
  value_attributes= value.attributes
252
+ # r attribute contains the location like A1
249
253
  cell_index = Parser.convert_to_index(value_attributes['r'].content)
250
- style_index = nil
254
+ style_index = 0
251
255
 
256
+ # t is optional and contains the type of the cell
252
257
  data_type = value_attributes['t'].content if value_attributes['t']
253
258
  element_hash ={}
254
259
  value.children.each do |node|
@@ -277,6 +282,7 @@ module RubyXL
277
282
  cell_data = Integer(v_element_content)
278
283
  end
279
284
  end
285
+ # f is the formula element
280
286
  cell_formula = nil
281
287
  fmla_css = element_hash["f_element"]
282
288
  if fmla_css && fmla_css.content
@@ -293,8 +299,6 @@ module RubyXL
293
299
 
294
300
  unless @data_only
295
301
  style_index = value['s'].to_i #nil goes to 0 (default)
296
- else
297
- style_index = 0
298
302
  end
299
303
 
300
304
  wb.worksheets[i].sheet_data[cell_index[0]][cell_index[1]] =
@@ -15,7 +15,7 @@ module RubyXL
15
15
  class Workbook
16
16
  include Enumerable
17
17
  attr_accessor :worksheets, :filepath, :creator, :modifier, :created_at,
18
- :modified_at, :company, :application, :appversion, :num_fmts, :fonts, :fills,
18
+ :modified_at, :company, :application, :appversion, :num_fmts, :num_fmts_hash, :fonts, :fills,
19
19
  :borders, :cell_xfs, :cell_style_xfs, :cell_styles, :shared_strings, :calc_chain,
20
20
  :num_strings, :size, :date1904, :external_links, :style_corrector, :drawings,
21
21
  :worksheet_rels, :printer_settings, :macros, :colors, :shared_strings_XML, :defined_names, :column_lookup_hash
@@ -39,6 +39,7 @@ module RubyXL
39
39
  @application = application
40
40
  @appversion = appversion
41
41
  @num_fmts = nil
42
+ @num_fmts_hash = nil
42
43
  @fonts = nil
43
44
  @fills = nil
44
45
  @borders = nil
@@ -82,6 +83,20 @@ module RubyXL
82
83
  worksheets.each{|i| yield i}
83
84
  end
84
85
 
86
+ def num_fmts_by_id
87
+
88
+ return @num_fmts_hash unless @num_fmts_hash.nil?
89
+ if num_fmts
90
+ @num_fmts_hash={}
91
+ num_fmts[:numFmt].each do |num_fmt|
92
+ @num_fmts_hash[num_fmt[:attributes][:numFmtId]]=num_fmt
93
+ end
94
+ @num_fmts_hash
95
+ else
96
+ {}
97
+ end
98
+ end
99
+
85
100
  #filepath of xlsx file (including file itself)
86
101
  def write(filepath=@filepath)
87
102
  validate_before_write
@@ -171,6 +171,8 @@ module Writer
171
171
  xml.sheetCalcPr('fullCalcOnLoad'=>'1')
172
172
 
173
173
  unless @worksheet.merged_cells.nil? || @worksheet.merged_cells.size==0
174
+ #There is some kind of bug here that when merged_cells is sometimes a hash and not an array
175
+ #initial attempt at a fix fails in corrupted excel documents leaving as is for now.
174
176
  xml.mergeCells {
175
177
  @worksheet.merged_cells.each do |merged_cell|
176
178
  xml.mergeCell('ref'=>merged_cell[:attributes][:ref].to_s)
data/rubyXL.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rubyXL}
8
- s.version = "1.2.8"
8
+ s.version = "1.2.9"
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-07-11}
12
+ s.date = %q{2012-07-26}
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 = [
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: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 8
9
+ - 9
10
10
  segments_generated: true
11
- version: 1.2.8
11
+ version: 1.2.9
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-07-11 00:00:00 -04:00
19
+ date: 2012-07-26 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency