rubyXL 1.1.5 → 1.1.6
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.
- data/VERSION +1 -1
- data/lib/rubyXL/worksheet.rb +36 -35
- data/lib/rubyXL/writer/workbook_writer.rb +8 -4
- data/lib/rubyXL/writer/worksheet_writer.rb +6 -3
- data/rubyXL.gemspec +3 -4
- metadata +20 -20
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.6
|
data/lib/rubyXL/worksheet.rb
CHANGED
@@ -33,11 +33,11 @@ class Worksheet < PrivateClass
|
|
33
33
|
|
34
34
|
def get_table(headers=[])
|
35
35
|
validate_workbook
|
36
|
-
|
36
|
+
|
37
37
|
if !headers.is_a?(Array)
|
38
38
|
headers = [headers]
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
row_num = find_first_row_with_content(headers)
|
42
42
|
|
43
43
|
if row_num.nil?
|
@@ -47,20 +47,21 @@ class Worksheet < PrivateClass
|
|
47
47
|
table_hash = {}
|
48
48
|
table_hash[:table] = []
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
header_row = @sheet_data[row_num]
|
51
|
+
header_row.each_with_index do |header_cell, index|
|
52
|
+
next if header_cell.nil? || header_cell.value.nil?
|
53
|
+
header = header_cell.value.to_s
|
54
|
+
table_hash[header] = []
|
54
55
|
|
55
56
|
original_row = row_num + 1
|
56
57
|
current_row = original_row
|
57
58
|
|
58
|
-
cell = @sheet_data[current_row][
|
59
|
+
cell = @sheet_data[current_row][index]
|
59
60
|
|
60
61
|
# makes array of hashes in table_hash[:table]
|
61
|
-
# as well as hash of arrays in table_hash[header
|
62
|
+
# as well as hash of arrays in table_hash[header]
|
62
63
|
while !cell.nil? && !cell.value.nil?
|
63
|
-
table_hash[header
|
64
|
+
table_hash[header] << cell.value
|
64
65
|
|
65
66
|
table_index = current_row - original_row
|
66
67
|
|
@@ -68,17 +69,17 @@ class Worksheet < PrivateClass
|
|
68
69
|
table_hash[:table][table_index] = {}
|
69
70
|
end
|
70
71
|
|
71
|
-
table_hash[:table][table_index][header
|
72
|
+
table_hash[:table][table_index][header] = cell.value
|
72
73
|
|
73
74
|
current_row += 1
|
74
75
|
if @sheet_data[current_row].nil?
|
75
76
|
cell = nil
|
76
77
|
else
|
77
|
-
cell = @sheet_data[current_row][
|
78
|
+
cell = @sheet_data[current_row][index]
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
81
|
-
|
82
|
+
|
82
83
|
return table_hash
|
83
84
|
end
|
84
85
|
|
@@ -374,11 +375,11 @@ class Worksheet < PrivateClass
|
|
374
375
|
|
375
376
|
def add_cell_obj(cell, overwrite=true)
|
376
377
|
validate_workbook
|
377
|
-
|
378
|
+
|
378
379
|
if cell.nil?
|
379
380
|
return cell
|
380
381
|
end
|
381
|
-
|
382
|
+
|
382
383
|
row = cell.row
|
383
384
|
column = cell.column
|
384
385
|
|
@@ -401,27 +402,27 @@ class Worksheet < PrivateClass
|
|
401
402
|
def delete_row(row_index=0)
|
402
403
|
validate_workbook
|
403
404
|
validate_nonnegative(row_index)
|
404
|
-
|
405
|
+
|
405
406
|
if row_index >= @sheet_data.size
|
406
407
|
return nil
|
407
408
|
end
|
408
|
-
|
409
|
+
|
409
410
|
deleted = @sheet_data.delete_at(row_index)
|
410
411
|
row_num = row_index+1
|
411
|
-
|
412
|
+
|
412
413
|
row_num.upto(@sheet_data.size) do |index|
|
413
414
|
@row_styles[(index-1).to_s] = deep_copy(@row_styles[index.to_s])
|
414
415
|
end
|
415
416
|
@row_styles.delete(@sheet_data.size.to_s)
|
416
|
-
|
417
|
+
|
417
418
|
#change row styles
|
418
419
|
# raise row_styles.inspect
|
419
|
-
|
420
|
+
|
420
421
|
#change cell row numbers
|
421
422
|
(row_index...(@sheet_data.size-1)).each do |index|
|
422
423
|
@sheet_data[index].map {|c| c.row -= 1 if c}
|
423
424
|
end
|
424
|
-
|
425
|
+
|
425
426
|
return deleted
|
426
427
|
end
|
427
428
|
|
@@ -485,11 +486,11 @@ class Worksheet < PrivateClass
|
|
485
486
|
def delete_column(col_index=0)
|
486
487
|
validate_workbook
|
487
488
|
validate_nonnegative(col_index)
|
488
|
-
|
489
|
+
|
489
490
|
if col_index >= @sheet_data[0].size
|
490
491
|
return nil
|
491
492
|
end
|
492
|
-
|
493
|
+
|
493
494
|
#delete column
|
494
495
|
@sheet_data.map {|r| r.delete_at(col_index)}
|
495
496
|
|
@@ -501,7 +502,7 @@ class Worksheet < PrivateClass
|
|
501
502
|
end
|
502
503
|
end
|
503
504
|
end
|
504
|
-
|
505
|
+
|
505
506
|
#shift column styles
|
506
507
|
#shift col styles 'left'
|
507
508
|
@cols.each do |col|
|
@@ -578,19 +579,19 @@ class Worksheet < PrivateClass
|
|
578
579
|
end
|
579
580
|
end
|
580
581
|
end
|
581
|
-
|
582
|
+
|
582
583
|
def insert_cell(row=0,col=0,data=nil,formula=nil,shift=nil)
|
583
584
|
validate_workbook
|
584
585
|
validate_nonnegative(row)
|
585
586
|
validate_nonnegative(col)
|
586
|
-
|
587
|
+
|
587
588
|
increase_rows(row)
|
588
589
|
increase_columns(col)
|
589
|
-
|
590
|
+
|
590
591
|
if shift && shift != :right && shift != :down
|
591
592
|
raise 'invalid shift option'
|
592
593
|
end
|
593
|
-
|
594
|
+
|
594
595
|
if shift == :right
|
595
596
|
@sheet_data[row].insert(col,nil)
|
596
597
|
(row...(@sheet_data[row].size)).each do |index|
|
@@ -604,10 +605,10 @@ class Worksheet < PrivateClass
|
|
604
605
|
@sheet_data[index][col] = @sheet_data[index-1][col]
|
605
606
|
end
|
606
607
|
end
|
607
|
-
|
608
|
+
|
608
609
|
return add_cell(row,col,data,formula)
|
609
610
|
end
|
610
|
-
|
611
|
+
|
611
612
|
# by default, only sets cell to nil
|
612
613
|
# if :left is specified, method will shift row contents to the right of the deleted cell to the left
|
613
614
|
# if :up is specified, method will shift column contents below the deleted cell upward
|
@@ -618,14 +619,14 @@ class Worksheet < PrivateClass
|
|
618
619
|
if @sheet_data.size <= row || @sheet_data[row].size <= col
|
619
620
|
return nil
|
620
621
|
end
|
621
|
-
|
622
|
+
|
622
623
|
cell = @sheet_data[row][col]
|
623
624
|
@sheet_data[row][col]=nil
|
624
|
-
|
625
|
+
|
625
626
|
if shift && shift != :left && shift != :up
|
626
627
|
raise 'invalid shift option'
|
627
628
|
end
|
628
|
-
|
629
|
+
|
629
630
|
if shift == :left
|
630
631
|
@sheet_data[row].delete_at(col)
|
631
632
|
@sheet_data[row] << nil
|
@@ -645,7 +646,7 @@ class Worksheet < PrivateClass
|
|
645
646
|
@sheet_data.last[col].row -= 1
|
646
647
|
end
|
647
648
|
end
|
648
|
-
|
649
|
+
|
649
650
|
return cell
|
650
651
|
end
|
651
652
|
|
@@ -1362,7 +1363,7 @@ class Worksheet < PrivateClass
|
|
1362
1363
|
@workbook.fills[xf[:fillId].to_s][:count] += 1
|
1363
1364
|
@workbook.borders[xf[:borderId].to_s][:count] += 1
|
1364
1365
|
end
|
1365
|
-
|
1366
|
+
|
1366
1367
|
# finds first row which contains at least all strings in cells_content
|
1367
1368
|
def find_first_row_with_content(cells_content)
|
1368
1369
|
validate_workbook
|
@@ -1376,6 +1377,6 @@ class Worksheet < PrivateClass
|
|
1376
1377
|
end
|
1377
1378
|
return nil
|
1378
1379
|
end
|
1379
|
-
|
1380
|
+
|
1380
1381
|
end #end class
|
1381
1382
|
end
|
@@ -23,7 +23,11 @@ module Writer
|
|
23
23
|
#attributes out of order here
|
24
24
|
xml.fileVersion('appName'=>'xl', 'lastEdited'=>'4','lowestEdited'=>'4','rupBuild'=>'4505')
|
25
25
|
#TODO following line - date 1904? check if mac only
|
26
|
-
|
26
|
+
if @workbook.date1904.nil? || @workbook.date1904.to_s == ''
|
27
|
+
xml.workbookPr('showInkAnnotation'=>'0', 'autoCompressPictures'=>'0')
|
28
|
+
else
|
29
|
+
xml.workbookPr('date1904'=>@workbook.date1904.to_s, 'showInkAnnotation'=>'0', 'autoCompressPictures'=>'0')
|
30
|
+
end
|
27
31
|
xml.bookViews {
|
28
32
|
#attributes out of order here
|
29
33
|
xml.workbookView('xWindow'=>'-20', 'yWindow'=>'-20',
|
@@ -44,8 +48,8 @@ module Writer
|
|
44
48
|
end
|
45
49
|
}
|
46
50
|
end
|
47
|
-
|
48
|
-
# nokogiri builder creates CDATA tag around content,
|
51
|
+
|
52
|
+
# nokogiri builder creates CDATA tag around content,
|
49
53
|
# using .text creates "html safe" < and > in place of < and >
|
50
54
|
# xml to hash method does not seem to function well for this particular piece of xml
|
51
55
|
xml.cdata @workbook.defined_names.to_s
|
@@ -68,7 +72,7 @@ module Writer
|
|
68
72
|
contents = contents.gsub(/<!\[CDATA\[(.*)\]\]>/,'\1')
|
69
73
|
contents = contents.sub(/<\?xml version=\"1.0\"\?>/,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\n")
|
70
74
|
puts '
|
71
|
-
|
75
|
+
|
72
76
|
'
|
73
77
|
puts contents
|
74
78
|
|
@@ -123,8 +123,11 @@ module Writer
|
|
123
123
|
#TODO do xml.c for all cases, inside specific.
|
124
124
|
# if dat.formula.nil?
|
125
125
|
dat.style_index = @workbook.style_corrector[dat.style_index.to_s]
|
126
|
-
|
127
|
-
|
126
|
+
c_opts = {'r'=>Cell.convert_to_cell(i,j), 's'=>dat.style_index.to_s}
|
127
|
+
unless dat.datatype.nil? || dat.datatype == ''
|
128
|
+
c_opts['t'] = dat.datatype
|
129
|
+
end
|
130
|
+
xml.c(c_opts) {
|
128
131
|
unless dat.formula.nil?
|
129
132
|
if dat.formula_attributes.nil? || dat.formula_attributes.empty?
|
130
133
|
xml.f dat.formula.to_s
|
@@ -191,7 +194,7 @@ module Writer
|
|
191
194
|
|
192
195
|
unless @worksheet.legacy_drawing.nil?
|
193
196
|
xml.legacyDrawing('r:id'=>@worksheet.legacy_drawing[:attributes][:id])
|
194
|
-
end
|
197
|
+
end
|
195
198
|
|
196
199
|
unless @worksheet.extLst.nil?
|
197
200
|
xml.extLst {
|
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.1.
|
8
|
+
s.version = "1.1.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{2011-09-
|
12
|
+
s.date = %q{2011-09-13}
|
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 = [
|
@@ -55,11 +55,10 @@ Gem::Specification.new do |s|
|
|
55
55
|
s.homepage = %q{http://github.com/gilt/rubyXL}
|
56
56
|
s.licenses = ["MIT"]
|
57
57
|
s.require_paths = ["lib"]
|
58
|
-
s.rubygems_version = %q{1.
|
58
|
+
s.rubygems_version = %q{1.4.2}
|
59
59
|
s.summary = %q{rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx/.xlsm) Documents}
|
60
60
|
|
61
61
|
if s.respond_to? :specification_version then
|
62
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
63
62
|
s.specification_version = 3
|
64
63
|
|
65
64
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyXL
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 31
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 6
|
10
|
+
version: 1.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vivek Bhagwat
|
@@ -15,13 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-13 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
type: :development
|
23
|
-
prerelease: false
|
24
|
-
name: shoulda
|
25
23
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
24
|
none: false
|
27
25
|
requirements:
|
@@ -32,10 +30,10 @@ dependencies:
|
|
32
30
|
- 0
|
33
31
|
version: "0"
|
34
32
|
requirement: *id001
|
33
|
+
prerelease: false
|
34
|
+
name: shoulda
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
type: :development
|
37
|
-
prerelease: false
|
38
|
-
name: bundler
|
39
37
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
38
|
none: false
|
41
39
|
requirements:
|
@@ -48,10 +46,10 @@ dependencies:
|
|
48
46
|
- 0
|
49
47
|
version: 1.0.0
|
50
48
|
requirement: *id002
|
49
|
+
prerelease: false
|
50
|
+
name: bundler
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
52
|
type: :development
|
53
|
-
prerelease: false
|
54
|
-
name: jeweler
|
55
53
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
54
|
none: false
|
57
55
|
requirements:
|
@@ -64,10 +62,10 @@ dependencies:
|
|
64
62
|
- 0
|
65
63
|
version: 1.6.0
|
66
64
|
requirement: *id003
|
65
|
+
prerelease: false
|
66
|
+
name: jeweler
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
type: :development
|
69
|
-
prerelease: false
|
70
|
-
name: rcov
|
71
69
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
70
|
none: false
|
73
71
|
requirements:
|
@@ -78,10 +76,10 @@ dependencies:
|
|
78
76
|
- 0
|
79
77
|
version: "0"
|
80
78
|
requirement: *id004
|
79
|
+
prerelease: false
|
80
|
+
name: rcov
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
type: :development
|
83
|
-
prerelease: false
|
84
|
-
name: nokogiri
|
85
83
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
84
|
none: false
|
87
85
|
requirements:
|
@@ -94,10 +92,10 @@ dependencies:
|
|
94
92
|
- 4
|
95
93
|
version: 1.4.4
|
96
94
|
requirement: *id005
|
95
|
+
prerelease: false
|
96
|
+
name: nokogiri
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
type: :development
|
99
|
-
prerelease: false
|
100
|
-
name: rubyzip
|
101
99
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
102
100
|
none: false
|
103
101
|
requirements:
|
@@ -110,10 +108,10 @@ dependencies:
|
|
110
108
|
- 4
|
111
109
|
version: 0.9.4
|
112
110
|
requirement: *id006
|
111
|
+
prerelease: false
|
112
|
+
name: rubyzip
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
type: :development
|
115
|
-
prerelease: false
|
116
|
-
name: rspec
|
117
115
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
118
116
|
none: false
|
119
117
|
requirements:
|
@@ -126,6 +124,8 @@ dependencies:
|
|
126
124
|
- 4
|
127
125
|
version: 1.3.4
|
128
126
|
requirement: *id007
|
127
|
+
prerelease: false
|
128
|
+
name: rspec
|
129
129
|
description: rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx/.xlsm) Documents
|
130
130
|
email: bhagwat.vivek@gmail.com
|
131
131
|
executables: []
|
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
requirements: []
|
201
201
|
|
202
202
|
rubyforge_project:
|
203
|
-
rubygems_version: 1.
|
203
|
+
rubygems_version: 1.4.2
|
204
204
|
signing_key:
|
205
205
|
specification_version: 3
|
206
206
|
summary: rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx/.xlsm) Documents
|