rubyXL 1.1.1 → 1.1.2
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/worksheet.rb +46 -0
- data/rubyXL.gemspec +1 -1
- data/spec/lib/worksheet_spec.rb +43 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
data/lib/worksheet.rb
CHANGED
@@ -26,6 +26,11 @@ class Worksheet < PrivateClass
|
|
26
26
|
return @sheet_data[row]
|
27
27
|
end
|
28
28
|
|
29
|
+
#returns 2d array of just the cell values (without style or formula information)
|
30
|
+
def extract_data
|
31
|
+
return @sheet_data.map {|row| row.map {|c| if c.is_a?(Cell) then c.value else nil end}}
|
32
|
+
end
|
33
|
+
|
29
34
|
def get_table(headers=[])
|
30
35
|
validate_workbook
|
31
36
|
|
@@ -573,6 +578,47 @@ class Worksheet < PrivateClass
|
|
573
578
|
end
|
574
579
|
end
|
575
580
|
end
|
581
|
+
|
582
|
+
# by default, only sets cell to nil
|
583
|
+
# if :left is specified, method will shift row contents to the right of the deleted cell to the left
|
584
|
+
# if :up is specified, method will shift column contents below the deleted cell upward
|
585
|
+
def delete_cell(row=0,col=0,shift=nil)
|
586
|
+
validate_workbook
|
587
|
+
validate_nonnegative(row)
|
588
|
+
validate_nonnegative(col)
|
589
|
+
if @sheet_data.size <= row || @sheet_data[row].size <= col
|
590
|
+
return nil
|
591
|
+
end
|
592
|
+
|
593
|
+
cell = @sheet_data[row][col]
|
594
|
+
@sheet_data[row][col]=nil
|
595
|
+
|
596
|
+
if shift && shift != :left && shift != :up
|
597
|
+
raise 'invalid shift option'
|
598
|
+
end
|
599
|
+
|
600
|
+
if shift == :left
|
601
|
+
@sheet_data[row].delete_at(col)
|
602
|
+
@sheet_data[row] << nil
|
603
|
+
(col...(@sheet_data[row].size)).each do |index|
|
604
|
+
if @sheet_data[row][index].is_a?(Cell)
|
605
|
+
@sheet_data[row][index].column -= 1
|
606
|
+
end
|
607
|
+
end
|
608
|
+
elsif shift == :up
|
609
|
+
(row...(@sheet_data.size-1)).each do |index|
|
610
|
+
@sheet_data[index][col] = @sheet_data[index+1][col]
|
611
|
+
if @sheet_data[index][col].is_a?(Cell)
|
612
|
+
@sheet_data[index][col].row -= 1
|
613
|
+
end
|
614
|
+
end
|
615
|
+
if @sheet_data.last[col].is_a?(Cell)
|
616
|
+
@sheet_data.last[col].row -= 1
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
return cell
|
621
|
+
end
|
576
622
|
|
577
623
|
def get_row_fill(row=0)
|
578
624
|
validate_workbook
|
data/rubyXL.gemspec
CHANGED
data/spec/lib/worksheet_spec.rb
CHANGED
@@ -17,6 +17,15 @@ describe RubyXL::Worksheet do
|
|
17
17
|
@old_cell_formula = @worksheet[0][0].formula
|
18
18
|
end
|
19
19
|
|
20
|
+
describe '.extract_data' do
|
21
|
+
it 'should return a 2d array of just the cell values (without style or formula information)' do
|
22
|
+
data = @worksheet.extract_data()
|
23
|
+
data[0][0].should == '0:0'
|
24
|
+
data.size.should == @worksheet.sheet_data.size
|
25
|
+
data[0].size.should == @worksheet[0].size
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
20
29
|
describe '.get_table' do
|
21
30
|
it 'should return nil if table cannot be found with specified string' do
|
22
31
|
@worksheet.get_table('TEST').should be_nil
|
@@ -1081,6 +1090,40 @@ describe RubyXL::Worksheet do
|
|
1081
1090
|
end
|
1082
1091
|
end
|
1083
1092
|
|
1093
|
+
describe '.delete_cell' do
|
1094
|
+
it 'should make a cell nil if no shift argument specified' do
|
1095
|
+
deleted = @worksheet.delete_cell(0,0)
|
1096
|
+
@worksheet[0][0].should be_nil
|
1097
|
+
@old_cell.inspect.should == deleted.inspect
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
it 'should return nil if a cell which is out of range is specified' do
|
1101
|
+
@worksheet.delete_cell(12,12).should be_nil
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
it 'should cause error if a negative argument is passed in' do
|
1105
|
+
lambda {
|
1106
|
+
@worksheet.delete_cell(-1,-1)
|
1107
|
+
}.should raise_error
|
1108
|
+
end
|
1109
|
+
|
1110
|
+
it 'should shift cells to the right of the deleted cell left if :left is specified' do
|
1111
|
+
@worksheet.delete_cell(0,0,:left)
|
1112
|
+
@worksheet[0][0].value.should == '0:1'
|
1113
|
+
end
|
1114
|
+
|
1115
|
+
it 'should shift cells below the deleted cell up if :up is specified' do
|
1116
|
+
@worksheet.delete_cell(0,0,:up)
|
1117
|
+
@worksheet[0][0].value.should == '1:0'
|
1118
|
+
end
|
1119
|
+
|
1120
|
+
it 'should cause en error if an argument other than :left, :up, or nil is specified for shift' do
|
1121
|
+
lambda {
|
1122
|
+
@worksheet.delete_cell(0,0,:down)
|
1123
|
+
}.should raise_error
|
1124
|
+
end
|
1125
|
+
end
|
1126
|
+
|
1084
1127
|
describe '.get_row_fill' do
|
1085
1128
|
it 'should return white (ffffff) if no fill color specified for row' do
|
1086
1129
|
@worksheet.get_row_fill(0).should == 'ffffff'
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 2
|
10
|
+
version: 1.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vivek Bhagwat
|