rubyXL 1.0.9 → 1.0.10
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/cell.rb +4 -1
- data/lib/workbook.rb +1 -0
- data/lib/worksheet.rb +61 -2
- data/rubyXL.gemspec +2 -2
- data/spec/lib/worksheet_spec.rb +57 -1
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.10
|
data/lib/cell.rb
CHANGED
@@ -304,7 +304,10 @@ module RubyXL
|
|
304
304
|
end
|
305
305
|
|
306
306
|
def inspect
|
307
|
-
"#{@row},#{@column}: #{@value}
|
307
|
+
str = "(#{@row},#{@column}): #{@value}"
|
308
|
+
str += " =#{@formula}" if @formula
|
309
|
+
str += ", datatype = #{@datatype}, style_index = #{@style_index}"
|
310
|
+
return str
|
308
311
|
end
|
309
312
|
|
310
313
|
private
|
data/lib/workbook.rb
CHANGED
data/lib/worksheet.rb
CHANGED
@@ -393,9 +393,36 @@ class Worksheet < PrivateClass
|
|
393
393
|
return @sheet_data[row][column]
|
394
394
|
end
|
395
395
|
|
396
|
+
def delete_row(row_index=0)
|
397
|
+
validate_workbook
|
398
|
+
validate_nonnegative(row_index)
|
399
|
+
|
400
|
+
if row_index >= @sheet_data.size
|
401
|
+
return nil
|
402
|
+
end
|
403
|
+
|
404
|
+
deleted = @sheet_data.delete_at(row_index)
|
405
|
+
row_num = row_index+1
|
406
|
+
|
407
|
+
row_num.upto(@sheet_data.size) do |index|
|
408
|
+
@row_styles[(index-1).to_s] = deep_copy(@row_styles[index.to_s])
|
409
|
+
end
|
410
|
+
@row_styles.delete(@sheet_data.size.to_s)
|
411
|
+
|
412
|
+
#change row styles
|
413
|
+
# raise row_styles.inspect
|
414
|
+
|
415
|
+
#change cell row numbers
|
416
|
+
(row_index...(@sheet_data.size-1)).each do |index|
|
417
|
+
@sheet_data[index].map {|c| c.row -= 1 if c}
|
418
|
+
end
|
419
|
+
|
420
|
+
return deleted
|
421
|
+
end
|
422
|
+
|
396
423
|
#inserts row at row_index, pushes down, copies style from below (row previously at that index)
|
397
424
|
#USE OF THIS METHOD will break formulas which reference cells which are being "pushed down"
|
398
|
-
def insert_row(row_index)
|
425
|
+
def insert_row(row_index=0)
|
399
426
|
validate_workbook
|
400
427
|
validate_nonnegative(row_index)
|
401
428
|
|
@@ -450,9 +477,41 @@ class Worksheet < PrivateClass
|
|
450
477
|
return @sheet_data[row_index]
|
451
478
|
end
|
452
479
|
|
480
|
+
def delete_column(col_index=0)
|
481
|
+
validate_workbook
|
482
|
+
validate_nonnegative(col_index)
|
483
|
+
|
484
|
+
if col_index >= @sheet_data[0].size
|
485
|
+
return nil
|
486
|
+
end
|
487
|
+
|
488
|
+
#delete column
|
489
|
+
@sheet_data.map {|r| r.delete_at(col_index)}
|
490
|
+
|
491
|
+
#change column numbers for cells to right of deleted column
|
492
|
+
@sheet_data.each_with_index do |row,row_index|
|
493
|
+
(col_index...(row.size)).each do |index|
|
494
|
+
if @sheet_data[row_index][index].is_a?(Cell)
|
495
|
+
@sheet_data[row_index][index].column -= 1
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
#shift column styles
|
501
|
+
#shift col styles 'left'
|
502
|
+
@cols.each do |col|
|
503
|
+
if Integer(col[:attributes][:min]) >= col_index
|
504
|
+
col[:attributes][:min] = (Integer(col[:attributes][:min]) - 1).to_s
|
505
|
+
end
|
506
|
+
if Integer(col[:attributes][:max]) >= col_index
|
507
|
+
col[:attributes][:max] = (Integer(col[:attributes][:max]) - 1).to_s
|
508
|
+
end
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
453
512
|
# inserts column at col_index, pushes everything right, takes styles from column to left
|
454
513
|
# USE OF THIS METHOD will break formulas which reference cells which are being "pushed down"
|
455
|
-
def insert_column(col_index)
|
514
|
+
def insert_column(col_index=0)
|
456
515
|
validate_workbook
|
457
516
|
validate_nonnegative(col_index)
|
458
517
|
increase_columns(col_index)
|
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.0.
|
8
|
+
s.version = "1.0.10"
|
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-08-
|
12
|
+
s.date = %q{2011-08-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 = [
|
data/spec/lib/worksheet_spec.rb
CHANGED
@@ -953,6 +953,34 @@ describe RubyXL::Worksheet do
|
|
953
953
|
end
|
954
954
|
end
|
955
955
|
|
956
|
+
describe '.delete_row' do
|
957
|
+
it 'should delete a row at index specified, "pushing" everything else "up"' do
|
958
|
+
@worksheet.delete_row(0)
|
959
|
+
@worksheet[0][0].value.should == "1:0"
|
960
|
+
@worksheet[0][0].formula.should be_nil
|
961
|
+
@worksheet[0][0].row.should == 0
|
962
|
+
@worksheet[0][0].column.should == 0
|
963
|
+
end
|
964
|
+
|
965
|
+
it 'should delete a row at index specified, adjusting styles for other rows' do
|
966
|
+
@worksheet.change_row_font_name(1,"Courier")
|
967
|
+
@worksheet.delete_row(0)
|
968
|
+
@worksheet.get_row_font_name(0).should == "Courier"
|
969
|
+
end
|
970
|
+
|
971
|
+
it 'should preserve (rather than fix) formulas that reference cells in "pushed up" rows' do
|
972
|
+
@worksheet.add_cell(11,0,nil,'SUM(A1:A10)')
|
973
|
+
@worksheet.delete_row(0)
|
974
|
+
@worksheet[10][0].formula.should == 'SUM(A1:A10)'
|
975
|
+
end
|
976
|
+
|
977
|
+
it 'should cause error if a negative argument is passed in' do
|
978
|
+
lambda {
|
979
|
+
@worksheet.delete_row(-1)
|
980
|
+
}.should raise_error
|
981
|
+
end
|
982
|
+
end
|
983
|
+
|
956
984
|
describe '.insert_row' do
|
957
985
|
it 'should insert a row at index specified, "pushing" everything else "down"' do
|
958
986
|
@worksheet.insert_row(0)
|
@@ -986,6 +1014,34 @@ describe RubyXL::Worksheet do
|
|
986
1014
|
end
|
987
1015
|
end
|
988
1016
|
|
1017
|
+
describe '.delete_column' do
|
1018
|
+
it 'should delete a column at index specified, "pushing" everything else "left"' do
|
1019
|
+
@worksheet.delete_column(0)
|
1020
|
+
@worksheet[0][0].value.should == "0:1"
|
1021
|
+
@worksheet[0][0].formula.should be_nil
|
1022
|
+
@worksheet[0][0].row.should == 0
|
1023
|
+
@worksheet[0][0].column.should == 0
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
it 'should delete a column at index specified, "pushing" styles "left"' do
|
1027
|
+
@worksheet.change_column_font_name(1,"Courier")
|
1028
|
+
@worksheet.delete_column(0)
|
1029
|
+
@worksheet.get_column_font_name(0).should == "Courier"
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
it 'should preserve (rather than fix) formulas that reference cells in "pushed left" columns' do
|
1033
|
+
@worksheet.add_cell(0,4,nil,'SUM(A1:D1)')
|
1034
|
+
@worksheet.delete_column(0)
|
1035
|
+
@worksheet[0][3].formula.should == 'SUM(A1:D1)'
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
it 'should cause error if negative argument is passed in' do
|
1039
|
+
lambda {
|
1040
|
+
@worksheet.delete_column(-1)
|
1041
|
+
}.should raise_error
|
1042
|
+
end
|
1043
|
+
end
|
1044
|
+
|
989
1045
|
describe '.insert_column' do
|
990
1046
|
it 'should insert a column at index specified, "pushing" everything else "right"' do
|
991
1047
|
@worksheet.insert_column(0)
|
@@ -1006,7 +1062,7 @@ describe RubyXL::Worksheet do
|
|
1006
1062
|
@worksheet.get_column_font_name(0).should == 'Verdana' #not courier
|
1007
1063
|
end
|
1008
1064
|
|
1009
|
-
it 'should preserve (rather than fix) formulas that reference cells in "pushed right"
|
1065
|
+
it 'should preserve (rather than fix) formulas that reference cells in "pushed right" column' do
|
1010
1066
|
@worksheet.add_cell(0,5,nil,'SUM(A1:D1)')
|
1011
1067
|
@worksheet.insert_column(0)
|
1012
1068
|
@worksheet[0][6].formula.should == 'SUM(A1:D1)'
|
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: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 10
|
10
|
+
version: 1.0.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vivek Bhagwat
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-10 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|