writeexcel 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +26 -31
- data/examples/a_simple.rb +42 -42
- data/examples/{autofilters.rb → autofilter.rb} +264 -266
- data/examples/bigfile.rb +29 -0
- data/examples/chart_area.rb +120 -0
- data/examples/chart_bar.rb +119 -0
- data/examples/chart_column.rb +119 -0
- data/examples/chart_line.rb +119 -0
- data/examples/chart_pie.rb +107 -0
- data/examples/chart_scatter.rb +120 -0
- data/examples/chart_stock.rb +147 -0
- data/examples/copyformat.rb +51 -51
- data/examples/data_validate.rb +278 -278
- data/examples/date_time.rb +86 -86
- data/examples/defined_name.rb +31 -0
- data/examples/demo.rb +120 -118
- data/examples/diag_border.rb +35 -35
- data/examples/formats.rb +489 -489
- data/examples/header.rb +136 -136
- data/examples/hidden.rb +28 -28
- data/examples/hyperlink.rb +42 -42
- data/examples/images.rb +52 -52
- data/examples/merge1.rb +39 -39
- data/examples/merge2.rb +44 -44
- data/examples/merge3.rb +65 -65
- data/examples/merge4.rb +82 -82
- data/examples/merge5.rb +79 -79
- data/examples/properties.rb +33 -0
- data/examples/properties_jp.rb +32 -0
- data/examples/protection.rb +46 -46
- data/examples/regions.rb +52 -52
- data/examples/repeat.rb +42 -42
- data/examples/stats.rb +75 -75
- data/examples/stocks.rb +80 -80
- data/examples/tab_colors.rb +30 -30
- data/examples/write_arrays.rb +82 -0
- data/lib/writeexcel.rb +1134 -18
- data/lib/writeexcel/biffwriter.rb +273 -260
- data/lib/writeexcel/chart.rb +2306 -217
- data/lib/writeexcel/charts/area.rb +152 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +61 -0
- data/lib/writeexcel/charts/line.rb +152 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +211 -0
- data/lib/writeexcel/excelformulaparser.rb +208 -195
- data/lib/writeexcel/format.rb +1697 -1108
- data/lib/writeexcel/formula.rb +1050 -986
- data/lib/writeexcel/olewriter.rb +322 -322
- data/lib/writeexcel/properties.rb +251 -250
- data/lib/writeexcel/storage_lite.rb +968 -0
- data/lib/writeexcel/workbook.rb +3294 -2630
- data/lib/writeexcel/worksheet.rb +9012 -6377
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/tc_all.rb +32 -31
- data/test/tc_biff.rb +104 -104
- data/test/tc_chart.rb +22 -22
- data/test/tc_example_match.rb +1944 -1280
- data/test/tc_format.rb +1254 -1267
- data/test/tc_formula.rb +63 -63
- data/test/tc_ole.rb +110 -110
- data/test/tc_storage_lite.rb +149 -0
- data/test/tc_workbook.rb +140 -115
- data/test/tc_worksheet.rb +115 -115
- data/test/test_00_IEEE_double.rb +14 -14
- data/test/test_01_add_worksheet.rb +12 -12
- data/test/test_02_merge_formats.rb +58 -58
- data/test/test_04_dimensions.rb +397 -397
- data/test/test_05_rows.rb +182 -182
- data/test/test_06_extsst.rb +80 -80
- data/test/test_11_date_time.rb +484 -484
- data/test/test_12_date_only.rb +506 -506
- data/test/test_13_date_seconds.rb +486 -486
- data/test/test_21_escher.rb +642 -629
- data/test/test_22_mso_drawing_group.rb +750 -739
- data/test/test_23_note.rb +78 -78
- data/test/test_24_txo.rb +80 -80
- data/test/test_25_position_object.rb +82 -0
- data/test/test_26_autofilter.rb +327 -327
- data/test/test_27_autofilter.rb +144 -144
- data/test/test_28_autofilter.rb +174 -174
- data/test/test_29_process_jpg.rb +681 -131
- data/test/test_30_validation_dval.rb +82 -82
- data/test/test_31_validation_dv_strings.rb +131 -131
- data/test/test_32_validation_dv_formula.rb +211 -211
- data/test/test_40_property_types.rb +191 -191
- data/test/test_41_properties.rb +238 -238
- data/test/test_42_set_properties.rb +442 -419
- data/test/test_50_name_stored.rb +305 -0
- data/test/test_51_name_print_area.rb +363 -0
- data/test/test_52_name_print_titles.rb +460 -0
- data/test/test_53_autofilter.rb +209 -0
- data/test/test_60_chart_generic.rb +576 -0
- data/test/test_61_chart_subclasses.rb +97 -0
- data/test/test_62_chart_formats.rb +270 -0
- data/test/test_63_chart_area_formats.rb +647 -0
- data/test/test_chartex.rb +35 -0
- data/test/ts_all.rb +46 -34
- data/writeexcel.gemspec +18 -0
- data/writeexcel.rdoc +583 -0
- metadata +162 -108
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/perl_output/demo.xls
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/perl_output/images.xls
CHANGED
Binary file
|
data/test/perl_output/merge1.xls
CHANGED
Binary file
|
data/test/perl_output/merge2.xls
CHANGED
Binary file
|
data/test/perl_output/merge3.xls
CHANGED
Binary file
|
data/test/perl_output/merge4.xls
CHANGED
Binary file
|
data/test/perl_output/merge5.xls
CHANGED
Binary file
|
Binary file
|
Binary file
|
data/test/perl_output/stats.xls
CHANGED
Binary file
|
data/test/perl_output/stocks.xls
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/tc_all.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
|
-
require "tc_biff"
|
2
|
-
require "tc_ole"
|
3
|
-
require "tc_workbook"
|
4
|
-
require "tc_worksheet"
|
5
|
-
require "tc_format"
|
6
|
-
require "tc_formula"
|
7
|
-
require 'tc_chart'
|
8
|
-
require "test_00_IEEE_double"
|
9
|
-
require 'test_01_add_worksheet'
|
10
|
-
require 'test_02_merge_formats'
|
11
|
-
require 'test_04_dimensions'
|
12
|
-
require 'test_05_rows'
|
13
|
-
require 'test_06_extsst'
|
14
|
-
require 'test_11_date_time'
|
15
|
-
require 'test_12_date_only'
|
16
|
-
require 'test_13_date_seconds'
|
17
|
-
require 'test_21_escher'
|
18
|
-
require 'test_22_mso_drawing_group'
|
19
|
-
require 'test_23_note'
|
20
|
-
require 'test_24_txo'
|
21
|
-
require 'test_26_autofilter'
|
22
|
-
require 'test_27_autofilter'
|
23
|
-
require 'test_28_autofilter'
|
24
|
-
require 'test_29_process_jpg'
|
25
|
-
require 'test_30_validation_dval'
|
26
|
-
require 'test_31_validation_dv_strings'
|
27
|
-
require 'test_32_validation_dv_formula'
|
28
|
-
require 'test_40_property_types'
|
29
|
-
require 'test_41_properties'
|
30
|
-
require 'test_42_set_properties'
|
31
|
-
require 'tc_example_match'
|
1
|
+
require "tc_biff"
|
2
|
+
require "tc_ole"
|
3
|
+
require "tc_workbook"
|
4
|
+
require "tc_worksheet"
|
5
|
+
require "tc_format"
|
6
|
+
require "tc_formula"
|
7
|
+
require 'tc_chart'
|
8
|
+
require "test_00_IEEE_double"
|
9
|
+
require 'test_01_add_worksheet'
|
10
|
+
require 'test_02_merge_formats'
|
11
|
+
require 'test_04_dimensions'
|
12
|
+
require 'test_05_rows'
|
13
|
+
require 'test_06_extsst'
|
14
|
+
require 'test_11_date_time'
|
15
|
+
require 'test_12_date_only'
|
16
|
+
require 'test_13_date_seconds'
|
17
|
+
require 'test_21_escher'
|
18
|
+
require 'test_22_mso_drawing_group'
|
19
|
+
require 'test_23_note'
|
20
|
+
require 'test_24_txo'
|
21
|
+
require 'test_26_autofilter'
|
22
|
+
require 'test_27_autofilter'
|
23
|
+
require 'test_28_autofilter'
|
24
|
+
require 'test_29_process_jpg'
|
25
|
+
require 'test_30_validation_dval'
|
26
|
+
require 'test_31_validation_dv_strings'
|
27
|
+
require 'test_32_validation_dv_formula'
|
28
|
+
require 'test_40_property_types'
|
29
|
+
require 'test_41_properties'
|
30
|
+
require 'test_42_set_properties'
|
31
|
+
require 'tc_example_match'
|
32
|
+
require 'tc_storage_lite'
|
data/test/tc_biff.rb
CHANGED
@@ -1,104 +1,104 @@
|
|
1
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require "writeexcel"
|
5
|
-
|
6
|
-
class TC_BIFFWriter < Test::Unit::TestCase
|
7
|
-
|
8
|
-
TEST_DIR = File.expand_path(File.dirname(__FILE__))
|
9
|
-
PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
|
10
|
-
|
11
|
-
def setup
|
12
|
-
t = Time.now.strftime("%Y%m%d")
|
13
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
14
|
-
@test_file = File.join(Dir.tmpdir, path)
|
15
|
-
@biff = BIFFWriter.new
|
16
|
-
@ruby_file = @test_file
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_append_no_error
|
20
|
-
assert_nothing_raised{ @biff.append("World") }
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_prepend_no_error
|
24
|
-
assert_nothing_raised{ @biff.prepend("Hello") }
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_data_added
|
28
|
-
assert_nothing_raised{ @biff.append("Hello", "World") }
|
29
|
-
data = ''
|
30
|
-
while d = @biff.get_data
|
31
|
-
data = data + d
|
32
|
-
end
|
33
|
-
assert_equal("HelloWorld", data, "Bad data contents")
|
34
|
-
assert_equal(10, @biff.datasize, "Bad data size")
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_data_prepended
|
38
|
-
|
39
|
-
assert_nothing_raised{ @biff.append("Hello") }
|
40
|
-
assert_nothing_raised{ @biff.prepend("World") }
|
41
|
-
data = ''
|
42
|
-
while d = @biff.get_data
|
43
|
-
data = data + d
|
44
|
-
end
|
45
|
-
assert_equal("WorldHello", data, "Bad data contents")
|
46
|
-
assert_equal(10, @biff.datasize, "Bad data size")
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_store_bof_length
|
50
|
-
assert_nothing_raised{ @biff.store_bof }
|
51
|
-
assert_equal(20, @biff.datasize, "Bad data size after store_bof call")
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_store_eof_length
|
55
|
-
assert_nothing_raised{ @biff.store_eof }
|
56
|
-
assert_equal(4, @biff.datasize, "Bad data size after store_eof call")
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_datasize_mixed
|
60
|
-
assert_nothing_raised{ @biff.append("Hello") }
|
61
|
-
assert_nothing_raised{ @biff.prepend("World") }
|
62
|
-
assert_nothing_raised{ @biff.store_bof }
|
63
|
-
assert_nothing_raised{ @biff.store_eof }
|
64
|
-
assert_equal(34, @biff.datasize, "Bad data size for mixed data")
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_add_continue
|
68
|
-
perl_file = "#{PERL_OUTDIR}/biff_add_continue_testdata"
|
69
|
-
size = File.size(perl_file)
|
70
|
-
@fh = File.new(@ruby_file,"w+")
|
71
|
-
@fh.print(@biff.add_continue('testdata'))
|
72
|
-
@fh.close
|
73
|
-
rsize = File.size(@ruby_file)
|
74
|
-
assert_equal(size,rsize,"File sizes not the same")
|
75
|
-
compare_file(perl_file, @ruby_file)
|
76
|
-
end
|
77
|
-
|
78
|
-
def teardown
|
79
|
-
@biff = nil
|
80
|
-
File.delete(@ruby_file) if File.exist?(@ruby_file)
|
81
|
-
end
|
82
|
-
|
83
|
-
def compare_file(expected, target)
|
84
|
-
fh_e = File.open(expected, "r")
|
85
|
-
fh_t = File.open(target, "r")
|
86
|
-
while true do
|
87
|
-
e1 = fh_e.read(1)
|
88
|
-
t1 = fh_t.read(1)
|
89
|
-
if e1.nil?
|
90
|
-
assert( t1.nil?, "#{expexted} is EOF but #{target} is NOT EOF.")
|
91
|
-
break
|
92
|
-
elsif t1.nil?
|
93
|
-
assert( e1.nil?, '#{target} is EOF but #{expected} is NOT EOF.')
|
94
|
-
break
|
95
|
-
end
|
96
|
-
assert_equal(e1, t1, sprintf(" #{expected} = '%s' but #{target} = '%s'", e1, t1))
|
97
|
-
break
|
98
|
-
end
|
99
|
-
fh_e.close
|
100
|
-
fh_t.close
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
end
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require "writeexcel"
|
5
|
+
|
6
|
+
class TC_BIFFWriter < Test::Unit::TestCase
|
7
|
+
|
8
|
+
TEST_DIR = File.expand_path(File.dirname(__FILE__))
|
9
|
+
PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
|
10
|
+
|
11
|
+
def setup
|
12
|
+
t = Time.now.strftime("%Y%m%d")
|
13
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
14
|
+
@test_file = File.join(Dir.tmpdir, path)
|
15
|
+
@biff = BIFFWriter.new
|
16
|
+
@ruby_file = @test_file
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_append_no_error
|
20
|
+
assert_nothing_raised{ @biff.append("World") }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_prepend_no_error
|
24
|
+
assert_nothing_raised{ @biff.prepend("Hello") }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_data_added
|
28
|
+
assert_nothing_raised{ @biff.append("Hello", "World") }
|
29
|
+
data = ''
|
30
|
+
while d = @biff.get_data
|
31
|
+
data = data + d
|
32
|
+
end
|
33
|
+
assert_equal("HelloWorld", data, "Bad data contents")
|
34
|
+
assert_equal(10, @biff.datasize, "Bad data size")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_data_prepended
|
38
|
+
|
39
|
+
assert_nothing_raised{ @biff.append("Hello") }
|
40
|
+
assert_nothing_raised{ @biff.prepend("World") }
|
41
|
+
data = ''
|
42
|
+
while d = @biff.get_data
|
43
|
+
data = data + d
|
44
|
+
end
|
45
|
+
assert_equal("WorldHello", data, "Bad data contents")
|
46
|
+
assert_equal(10, @biff.datasize, "Bad data size")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_store_bof_length
|
50
|
+
assert_nothing_raised{ @biff.store_bof }
|
51
|
+
assert_equal(20, @biff.datasize, "Bad data size after store_bof call")
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_store_eof_length
|
55
|
+
assert_nothing_raised{ @biff.store_eof }
|
56
|
+
assert_equal(4, @biff.datasize, "Bad data size after store_eof call")
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_datasize_mixed
|
60
|
+
assert_nothing_raised{ @biff.append("Hello") }
|
61
|
+
assert_nothing_raised{ @biff.prepend("World") }
|
62
|
+
assert_nothing_raised{ @biff.store_bof }
|
63
|
+
assert_nothing_raised{ @biff.store_eof }
|
64
|
+
assert_equal(34, @biff.datasize, "Bad data size for mixed data")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_add_continue
|
68
|
+
perl_file = "#{PERL_OUTDIR}/biff_add_continue_testdata"
|
69
|
+
size = File.size(perl_file)
|
70
|
+
@fh = File.new(@ruby_file,"w+")
|
71
|
+
@fh.print(@biff.add_continue('testdata'))
|
72
|
+
@fh.close
|
73
|
+
rsize = File.size(@ruby_file)
|
74
|
+
assert_equal(size,rsize,"File sizes not the same")
|
75
|
+
compare_file(perl_file, @ruby_file)
|
76
|
+
end
|
77
|
+
|
78
|
+
def teardown
|
79
|
+
@biff = nil
|
80
|
+
File.delete(@ruby_file) if File.exist?(@ruby_file)
|
81
|
+
end
|
82
|
+
|
83
|
+
def compare_file(expected, target)
|
84
|
+
fh_e = File.open(expected, "r")
|
85
|
+
fh_t = File.open(target, "r")
|
86
|
+
while true do
|
87
|
+
e1 = fh_e.read(1)
|
88
|
+
t1 = fh_t.read(1)
|
89
|
+
if e1.nil?
|
90
|
+
assert( t1.nil?, "#{expexted} is EOF but #{target} is NOT EOF.")
|
91
|
+
break
|
92
|
+
elsif t1.nil?
|
93
|
+
assert( e1.nil?, '#{target} is EOF but #{expected} is NOT EOF.')
|
94
|
+
break
|
95
|
+
end
|
96
|
+
assert_equal(e1, t1, sprintf(" #{expected} = '%s' but #{target} = '%s'", e1, t1))
|
97
|
+
break
|
98
|
+
end
|
99
|
+
fh_e.close
|
100
|
+
fh_t.close
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
end
|
data/test/tc_chart.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
#####################################################
|
2
|
-
# tc_chart.rb
|
3
|
-
#
|
4
|
-
# Test suite for the Chart class (chart.rb)
|
5
|
-
#####################################################
|
6
|
-
base = File.basename(Dir.pwd)
|
7
|
-
if base == "test" || base =~ /spreadsheet/i
|
8
|
-
Dir.chdir("..") if base == "test"
|
9
|
-
$LOAD_PATH.unshift(Dir.pwd + "/lib/spreadsheet")
|
10
|
-
Dir.chdir("test") rescue nil
|
11
|
-
end
|
12
|
-
|
13
|
-
require "test/unit"
|
14
|
-
require "writeexcel"
|
15
|
-
|
16
|
-
class TC_Chart < Test::Unit::TestCase
|
17
|
-
|
18
|
-
def test_
|
19
|
-
assert(true)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
1
|
+
#####################################################
|
2
|
+
# tc_chart.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Chart class (chart.rb)
|
5
|
+
#####################################################
|
6
|
+
base = File.basename(Dir.pwd)
|
7
|
+
if base == "test" || base =~ /spreadsheet/i
|
8
|
+
Dir.chdir("..") if base == "test"
|
9
|
+
$LOAD_PATH.unshift(Dir.pwd + "/lib/spreadsheet")
|
10
|
+
Dir.chdir("test") rescue nil
|
11
|
+
end
|
12
|
+
|
13
|
+
require "test/unit"
|
14
|
+
require "writeexcel"
|
15
|
+
|
16
|
+
class TC_Chart < Test::Unit::TestCase
|
17
|
+
|
18
|
+
def test_
|
19
|
+
assert(true)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/test/tc_example_match.rb
CHANGED
@@ -1,1280 +1,1944 @@
|
|
1
|
-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require 'writeexcel'
|
5
|
-
|
6
|
-
class TC_example_match < Test::Unit::TestCase
|
7
|
-
|
8
|
-
TEST_DIR = File.expand_path(File.dirname(__FILE__))
|
9
|
-
PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
|
10
|
-
|
11
|
-
def setup
|
12
|
-
t = Time.now.strftime("%Y%m%d")
|
13
|
-
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
14
|
-
@test_file = File.join(Dir.tmpdir, path)
|
15
|
-
@filename = @test_file
|
16
|
-
@filename2 = @test_file + "2"
|
17
|
-
end
|
18
|
-
|
19
|
-
def teardown
|
20
|
-
File.delete(@filename) if File.exist?(@filename)
|
21
|
-
File.delete(@filename2) if File.exist?(@filename2)
|
22
|
-
end
|
23
|
-
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
worksheet.write(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
#
|
44
|
-
worksheet.write(
|
45
|
-
worksheet.write(
|
46
|
-
|
47
|
-
|
48
|
-
# Write
|
49
|
-
worksheet.write(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
workbook.
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
#
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
#
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
#
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
#
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
#
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
#
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
#
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
compare_file("#{PERL_OUTDIR}/
|
254
|
-
end
|
255
|
-
|
256
|
-
def
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
#
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
#
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
#
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
worksheet.write(
|
378
|
-
worksheet.
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
worksheet.write(
|
392
|
-
worksheet.
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
#
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
worksheet.
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
#
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
#
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
worksheet.
|
505
|
-
worksheet.
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
#
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
#
|
606
|
-
#
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
#
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
#
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
#
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
#
|
682
|
-
#
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
#
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
#
|
713
|
-
#
|
714
|
-
#
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
worksheet
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
#
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
#
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
workbook.close
|
805
|
-
|
806
|
-
# do assertion
|
807
|
-
compare_file("#{PERL_OUTDIR}/
|
808
|
-
end
|
809
|
-
|
810
|
-
def
|
811
|
-
workbook
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
workbook.
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
#
|
831
|
-
|
832
|
-
worksheet
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
#
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
#
|
859
|
-
#
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
#
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
worksheet.
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
workbook.
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
worksheet
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
#
|
941
|
-
worksheet.
|
942
|
-
worksheet.
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
#
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
#
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
worksheet1.
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
#
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
#
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
#
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
workbook.close
|
1125
|
-
|
1126
|
-
# do assertion
|
1127
|
-
compare_file("#{PERL_OUTDIR}/
|
1128
|
-
end
|
1129
|
-
|
1130
|
-
def
|
1131
|
-
workbook
|
1132
|
-
worksheet
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
#
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
worksheet
|
1144
|
-
worksheet.
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
#
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
worksheet.write('
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
#
|
1210
|
-
#
|
1211
|
-
#
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
#
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
|
3
|
+
require "test/unit"
|
4
|
+
require 'writeexcel'
|
5
|
+
|
6
|
+
class TC_example_match < Test::Unit::TestCase
|
7
|
+
|
8
|
+
TEST_DIR = File.expand_path(File.dirname(__FILE__))
|
9
|
+
PERL_OUTDIR = File.join(TEST_DIR, 'perl_output')
|
10
|
+
|
11
|
+
def setup
|
12
|
+
t = Time.now.strftime("%Y%m%d")
|
13
|
+
path = "temp#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
14
|
+
@test_file = File.join(Dir.tmpdir, path)
|
15
|
+
@filename = @test_file
|
16
|
+
@filename2 = @test_file + "2"
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
File.delete(@filename) if File.exist?(@filename)
|
21
|
+
File.delete(@filename2) if File.exist?(@filename2)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_compare_file
|
25
|
+
expected = target = __FILE__
|
26
|
+
compare_file(expected, target)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_a_simple
|
30
|
+
workbook = WriteExcel.new(@filename);
|
31
|
+
worksheet = workbook.add_worksheet
|
32
|
+
|
33
|
+
# The general syntax is write(row, column, token). Note that row and
|
34
|
+
# column are zero indexed
|
35
|
+
#
|
36
|
+
|
37
|
+
# Write some text
|
38
|
+
worksheet.write(0, 0, "Hi Excel!")
|
39
|
+
|
40
|
+
|
41
|
+
# Write some numbers
|
42
|
+
worksheet.write(2, 0, 3) # Writes 3
|
43
|
+
worksheet.write(3, 0, 3.00000) # Writes 3
|
44
|
+
worksheet.write(4, 0, 3.00001) # Writes 3.00001
|
45
|
+
worksheet.write(5, 0, 3.14159) # TeX revision no.?
|
46
|
+
|
47
|
+
|
48
|
+
# Write some formulas
|
49
|
+
worksheet.write(7, 0, '=A3 + A6')
|
50
|
+
worksheet.write(8, 0, '=IF(A5>3,"Yes", "No")')
|
51
|
+
|
52
|
+
|
53
|
+
# Write a hyperlink
|
54
|
+
worksheet.write(10, 0, 'http://www.perl.com/')
|
55
|
+
|
56
|
+
# File save
|
57
|
+
workbook.close
|
58
|
+
|
59
|
+
# do assertion
|
60
|
+
compare_file("#{PERL_OUTDIR}/a_simple.xls", @filename)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_autofilter
|
64
|
+
workbook = WriteExcel.new(@filename)
|
65
|
+
|
66
|
+
worksheet1 = workbook.add_worksheet
|
67
|
+
worksheet2 = workbook.add_worksheet
|
68
|
+
worksheet3 = workbook.add_worksheet
|
69
|
+
worksheet4 = workbook.add_worksheet
|
70
|
+
worksheet5 = workbook.add_worksheet
|
71
|
+
worksheet6 = workbook.add_worksheet
|
72
|
+
|
73
|
+
bold = workbook.add_format(:bold => 1)
|
74
|
+
|
75
|
+
# Extract the data embedded at the end of this file.
|
76
|
+
headings = %w(Region Item Volume Month)
|
77
|
+
data = get_data_for_autofilter
|
78
|
+
|
79
|
+
# Set up several sheets with the same data.
|
80
|
+
workbook.sheets.each do |worksheet|
|
81
|
+
worksheet.set_column('A:D', 12)
|
82
|
+
worksheet.set_row(0, 20, bold)
|
83
|
+
worksheet.write('A1', headings)
|
84
|
+
end
|
85
|
+
|
86
|
+
###############################################################################
|
87
|
+
#
|
88
|
+
# Example 1. Autofilter without conditions.
|
89
|
+
#
|
90
|
+
|
91
|
+
worksheet1.autofilter('A1:D51')
|
92
|
+
worksheet1.write('A2', [data])
|
93
|
+
|
94
|
+
###############################################################################
|
95
|
+
#
|
96
|
+
#
|
97
|
+
# Example 2. Autofilter with a filter condition in the first column.
|
98
|
+
#
|
99
|
+
|
100
|
+
# The range in this example is the same as above but in row-column notation.
|
101
|
+
worksheet2.autofilter(0, 0, 50, 3)
|
102
|
+
|
103
|
+
# The placeholder "Region" in the filter is ignored and can be any string
|
104
|
+
# that adds clarity to the expression.
|
105
|
+
#
|
106
|
+
worksheet2.filter_column(0, 'Region eq East')
|
107
|
+
|
108
|
+
#
|
109
|
+
# Hide the rows that don't match the filter criteria.
|
110
|
+
#
|
111
|
+
row = 1
|
112
|
+
|
113
|
+
data.each do |row_data|
|
114
|
+
region = row_data[0]
|
115
|
+
|
116
|
+
if region == 'East'
|
117
|
+
# Row is visible.
|
118
|
+
else
|
119
|
+
# Hide row.
|
120
|
+
worksheet2.set_row(row, nil, nil, 1)
|
121
|
+
end
|
122
|
+
|
123
|
+
worksheet2.write(row, 0, row_data)
|
124
|
+
row += 1
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
###############################################################################
|
129
|
+
#
|
130
|
+
#
|
131
|
+
# Example 3. Autofilter with a dual filter condition in one of the columns.
|
132
|
+
#
|
133
|
+
|
134
|
+
worksheet3.autofilter('A1:D51')
|
135
|
+
|
136
|
+
worksheet3.filter_column('A', 'x eq East or x eq South')
|
137
|
+
|
138
|
+
#
|
139
|
+
# Hide the rows that don't match the filter criteria.
|
140
|
+
#
|
141
|
+
row = 1
|
142
|
+
|
143
|
+
data.each do |row_data|
|
144
|
+
region = row_data[0]
|
145
|
+
|
146
|
+
if region == 'East' || region == 'South'
|
147
|
+
# Row is visible.
|
148
|
+
else
|
149
|
+
# Hide row.
|
150
|
+
worksheet3.set_row(row, nil, nil, 1)
|
151
|
+
end
|
152
|
+
|
153
|
+
worksheet3.write(row, 0, row_data)
|
154
|
+
row += 1
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
###############################################################################
|
159
|
+
#
|
160
|
+
#
|
161
|
+
# Example 4. Autofilter with filter conditions in two columns.
|
162
|
+
#
|
163
|
+
|
164
|
+
worksheet4.autofilter('A1:D51')
|
165
|
+
|
166
|
+
worksheet4.filter_column('A', 'x eq East')
|
167
|
+
worksheet4.filter_column('C', 'x > 3000 and x < 8000' )
|
168
|
+
|
169
|
+
#
|
170
|
+
# Hide the rows that don't match the filter criteria.
|
171
|
+
#
|
172
|
+
row = 1
|
173
|
+
|
174
|
+
data.each do |row_data|
|
175
|
+
region = row_data[0]
|
176
|
+
volume = row_data[2]
|
177
|
+
|
178
|
+
if region == 'East' && volume > 3000 && volume < 8000
|
179
|
+
# Row is visible.
|
180
|
+
else
|
181
|
+
# Hide row.
|
182
|
+
worksheet4.set_row(row, nil, nil, 1)
|
183
|
+
end
|
184
|
+
|
185
|
+
worksheet4.write(row, 0, row_data)
|
186
|
+
row += 1
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
###############################################################################
|
191
|
+
#
|
192
|
+
#
|
193
|
+
# Example 5. Autofilter with filter for blanks.
|
194
|
+
#
|
195
|
+
|
196
|
+
# Create a blank cell in our test data.
|
197
|
+
data[5][0] = ''
|
198
|
+
|
199
|
+
worksheet5.autofilter('A1:D51')
|
200
|
+
worksheet5.filter_column('A', 'x == Blanks')
|
201
|
+
|
202
|
+
#
|
203
|
+
# Hide the rows that don't match the filter criteria.
|
204
|
+
#
|
205
|
+
row = 1
|
206
|
+
|
207
|
+
data.each do |row_data|
|
208
|
+
region = row_data[0]
|
209
|
+
|
210
|
+
if region == ''
|
211
|
+
# Row is visible.
|
212
|
+
else
|
213
|
+
# Hide row.
|
214
|
+
worksheet5.set_row(row, nil, nil, 1)
|
215
|
+
end
|
216
|
+
|
217
|
+
worksheet5.write(row, 0, row_data)
|
218
|
+
row += 1
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
###############################################################################
|
223
|
+
#
|
224
|
+
#
|
225
|
+
# Example 6. Autofilter with filter for non-blanks.
|
226
|
+
#
|
227
|
+
|
228
|
+
worksheet6.autofilter('A1:D51')
|
229
|
+
worksheet6.filter_column('A', 'x == NonBlanks')
|
230
|
+
|
231
|
+
#
|
232
|
+
# Hide the rows that don't match the filter criteria.
|
233
|
+
#
|
234
|
+
row = 1
|
235
|
+
|
236
|
+
data.each do |row_data|
|
237
|
+
region = row_data[0]
|
238
|
+
|
239
|
+
if region != ''
|
240
|
+
# Row is visible.
|
241
|
+
else
|
242
|
+
# Hide row.
|
243
|
+
worksheet6.set_row(row, nil, nil, 1)
|
244
|
+
end
|
245
|
+
|
246
|
+
worksheet6.write(row, 0, row_data)
|
247
|
+
row += 1
|
248
|
+
end
|
249
|
+
|
250
|
+
workbook.close
|
251
|
+
|
252
|
+
# do assertion
|
253
|
+
compare_file("#{PERL_OUTDIR}/autofilter.xls", @filename)
|
254
|
+
end
|
255
|
+
|
256
|
+
def get_data_for_autofilter
|
257
|
+
[
|
258
|
+
['East', 'Apple', 9000, 'July'],
|
259
|
+
['East', 'Apple', 5000, 'July'],
|
260
|
+
['South', 'Orange', 9000, 'September'],
|
261
|
+
['North', 'Apple', 2000, 'November'],
|
262
|
+
['West', 'Apple', 9000, 'November'],
|
263
|
+
['South', 'Pear', 7000, 'October'],
|
264
|
+
['North', 'Pear', 9000, 'August'],
|
265
|
+
['West', 'Orange', 1000, 'December'],
|
266
|
+
['West', 'Grape', 1000, 'November'],
|
267
|
+
['South', 'Pear', 10000, 'April'],
|
268
|
+
['West', 'Grape', 6000, 'January'],
|
269
|
+
['South', 'Orange', 3000, 'May'],
|
270
|
+
['North', 'Apple', 3000, 'December'],
|
271
|
+
['South', 'Apple', 7000, 'February'],
|
272
|
+
['West', 'Grape', 1000, 'December'],
|
273
|
+
['East', 'Grape', 8000, 'February'],
|
274
|
+
['South', 'Grape', 10000, 'June'],
|
275
|
+
['West', 'Pear', 7000, 'December'],
|
276
|
+
['South', 'Apple', 2000, 'October'],
|
277
|
+
['East', 'Grape', 7000, 'December'],
|
278
|
+
['North', 'Grape', 6000, 'April'],
|
279
|
+
['East', 'Pear', 8000, 'February'],
|
280
|
+
['North', 'Apple', 7000, 'August'],
|
281
|
+
['North', 'Orange', 7000, 'July'],
|
282
|
+
['North', 'Apple', 6000, 'June'],
|
283
|
+
['South', 'Grape', 8000, 'September'],
|
284
|
+
['West', 'Apple', 3000, 'October'],
|
285
|
+
['South', 'Orange', 10000, 'November'],
|
286
|
+
['West', 'Grape', 4000, 'July'],
|
287
|
+
['North', 'Orange', 5000, 'August'],
|
288
|
+
['East', 'Orange', 1000, 'November'],
|
289
|
+
['East', 'Orange', 4000, 'October'],
|
290
|
+
['North', 'Grape', 5000, 'August'],
|
291
|
+
['East', 'Apple', 1000, 'December'],
|
292
|
+
['South', 'Apple', 10000, 'March'],
|
293
|
+
['East', 'Grape', 7000, 'October'],
|
294
|
+
['West', 'Grape', 1000, 'September'],
|
295
|
+
['East', 'Grape', 10000, 'October'],
|
296
|
+
['South', 'Orange', 8000, 'March'],
|
297
|
+
['North', 'Apple', 4000, 'July'],
|
298
|
+
['South', 'Orange', 5000, 'July'],
|
299
|
+
['West', 'Apple', 4000, 'June'],
|
300
|
+
['East', 'Apple', 5000, 'April'],
|
301
|
+
['North', 'Pear', 3000, 'August'],
|
302
|
+
['East', 'Grape', 9000, 'November'],
|
303
|
+
['North', 'Orange', 8000, 'October'],
|
304
|
+
['East', 'Apple', 10000, 'June'],
|
305
|
+
['South', 'Pear', 1000, 'December'],
|
306
|
+
['North', 'Grape', 10000, 'July'],
|
307
|
+
['East', 'Grape', 6000, 'February'],
|
308
|
+
]
|
309
|
+
end
|
310
|
+
|
311
|
+
def test_regions
|
312
|
+
workbook = WriteExcel.new(@filename)
|
313
|
+
|
314
|
+
# Add some worksheets
|
315
|
+
north = workbook.add_worksheet("North")
|
316
|
+
south = workbook.add_worksheet("South")
|
317
|
+
east = workbook.add_worksheet("East")
|
318
|
+
west = workbook.add_worksheet("West")
|
319
|
+
|
320
|
+
# Add a Format
|
321
|
+
format = workbook.add_format()
|
322
|
+
format.set_bold()
|
323
|
+
format.set_color('blue')
|
324
|
+
|
325
|
+
# Add a caption to each worksheet
|
326
|
+
workbook.sheets.each do |worksheet|
|
327
|
+
worksheet.write(0, 0, "Sales", format)
|
328
|
+
end
|
329
|
+
|
330
|
+
# Write some data
|
331
|
+
north.write(0, 1, 200000)
|
332
|
+
south.write(0, 1, 100000)
|
333
|
+
east.write(0, 1, 150000)
|
334
|
+
west.write(0, 1, 100000)
|
335
|
+
|
336
|
+
# Set the active worksheet
|
337
|
+
bp=1
|
338
|
+
south.activate()
|
339
|
+
|
340
|
+
# Set the width of the first column
|
341
|
+
south.set_column(0, 0, 20)
|
342
|
+
|
343
|
+
# Set the active cell
|
344
|
+
south.set_selection(0, 1)
|
345
|
+
|
346
|
+
workbook.close
|
347
|
+
|
348
|
+
# do assertion
|
349
|
+
compare_file("#{PERL_OUTDIR}/regions.xls", @filename)
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_stats
|
353
|
+
workbook = WriteExcel.new(@filename)
|
354
|
+
worksheet = workbook.add_worksheet('Test data')
|
355
|
+
|
356
|
+
# Set the column width for columns 1
|
357
|
+
worksheet.set_column(0, 0, 20)
|
358
|
+
|
359
|
+
# Create a format for the headings
|
360
|
+
format = workbook.add_format
|
361
|
+
format.set_bold
|
362
|
+
|
363
|
+
# Write the sample data
|
364
|
+
worksheet.write(0, 0, 'Sample', format)
|
365
|
+
worksheet.write(0, 1, 1)
|
366
|
+
worksheet.write(0, 2, 2)
|
367
|
+
worksheet.write(0, 3, 3)
|
368
|
+
worksheet.write(0, 4, 4)
|
369
|
+
worksheet.write(0, 5, 5)
|
370
|
+
worksheet.write(0, 6, 6)
|
371
|
+
worksheet.write(0, 7, 7)
|
372
|
+
worksheet.write(0, 8, 8)
|
373
|
+
|
374
|
+
worksheet.write(1, 0, 'Length', format)
|
375
|
+
worksheet.write(1, 1, 25.4)
|
376
|
+
worksheet.write(1, 2, 25.4)
|
377
|
+
worksheet.write(1, 3, 24.8)
|
378
|
+
worksheet.write(1, 4, 25.0)
|
379
|
+
worksheet.write(1, 5, 25.3)
|
380
|
+
worksheet.write(1, 6, 24.9)
|
381
|
+
worksheet.write(1, 7, 25.2)
|
382
|
+
worksheet.write(1, 8, 24.8)
|
383
|
+
|
384
|
+
# Write some statistical functions
|
385
|
+
worksheet.write(4, 0, 'Count', format)
|
386
|
+
worksheet.write(4, 1, '=COUNT(B1:I1)')
|
387
|
+
|
388
|
+
worksheet.write(5, 0, 'Sum', format)
|
389
|
+
worksheet.write(5, 1, '=SUM(B2:I2)')
|
390
|
+
|
391
|
+
worksheet.write(6, 0, 'Average', format)
|
392
|
+
worksheet.write(6, 1, '=AVERAGE(B2:I2)')
|
393
|
+
|
394
|
+
worksheet.write(7, 0, 'Min', format)
|
395
|
+
worksheet.write(7, 1, '=MIN(B2:I2)')
|
396
|
+
|
397
|
+
worksheet.write(8, 0, 'Max', format)
|
398
|
+
worksheet.write(8, 1, '=MAX(B2:I2)')
|
399
|
+
|
400
|
+
worksheet.write(9, 0, 'Standard Deviation', format)
|
401
|
+
worksheet.write(9, 1, '=STDEV(B2:I2)')
|
402
|
+
|
403
|
+
worksheet.write(10, 0, 'Kurtosis', format)
|
404
|
+
worksheet.write(10, 1, '=KURT(B2:I2)')
|
405
|
+
|
406
|
+
workbook.close
|
407
|
+
|
408
|
+
# do assertion
|
409
|
+
compare_file("#{PERL_OUTDIR}/stats.xls", @filename)
|
410
|
+
end
|
411
|
+
|
412
|
+
def test_hyperlink1
|
413
|
+
# Create a new workbook and add a worksheet
|
414
|
+
workbook = WriteExcel.new(@filename)
|
415
|
+
worksheet = workbook.add_worksheet('Hyperlinks')
|
416
|
+
|
417
|
+
# Format the first column
|
418
|
+
worksheet.set_column('A:A', 30)
|
419
|
+
worksheet.set_selection('B1')
|
420
|
+
|
421
|
+
|
422
|
+
# Add a sample format
|
423
|
+
format = workbook.add_format
|
424
|
+
format.set_size(12)
|
425
|
+
format.set_bold
|
426
|
+
format.set_color('red')
|
427
|
+
format.set_underline
|
428
|
+
|
429
|
+
|
430
|
+
# Write some hyperlinks
|
431
|
+
worksheet.write('A1', 'http://www.perl.com/' )
|
432
|
+
worksheet.write('A3', 'http://www.perl.com/', 'Perl home' )
|
433
|
+
worksheet.write('A5', 'http://www.perl.com/', nil, format)
|
434
|
+
worksheet.write('A7', 'mailto:jmcnamara@cpan.org', 'Mail me')
|
435
|
+
|
436
|
+
# Write a URL that isn't a hyperlink
|
437
|
+
worksheet.write_string('A9', 'http://www.perl.com/')
|
438
|
+
|
439
|
+
workbook.close
|
440
|
+
|
441
|
+
# do assertion
|
442
|
+
compare_file("#{PERL_OUTDIR}/hyperlink.xls", @filename)
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_copyformat
|
446
|
+
# Create workbook1
|
447
|
+
workbook1 = WriteExcel.new(@filename)
|
448
|
+
worksheet1 = workbook1.add_worksheet
|
449
|
+
format1a = workbook1.add_format
|
450
|
+
format1b = workbook1.add_format
|
451
|
+
|
452
|
+
# Create workbook2
|
453
|
+
workbook2 = WriteExcel.new(@filename2)
|
454
|
+
worksheet2 = workbook2.add_worksheet
|
455
|
+
format2a = workbook2.add_format
|
456
|
+
format2b = workbook2.add_format
|
457
|
+
|
458
|
+
# Create a global format object that isn't tied to a workbook
|
459
|
+
global_format = Format.new
|
460
|
+
|
461
|
+
# Set the formatting
|
462
|
+
global_format.set_color('blue')
|
463
|
+
global_format.set_bold
|
464
|
+
global_format.set_italic
|
465
|
+
|
466
|
+
# Create another example format
|
467
|
+
format1b.set_color('red')
|
468
|
+
|
469
|
+
# Copy the global format properties to the worksheet formats
|
470
|
+
format1a.copy(global_format)
|
471
|
+
format2a.copy(global_format)
|
472
|
+
|
473
|
+
# Copy a format from worksheet1 to worksheet2
|
474
|
+
format2b.copy(format1b)
|
475
|
+
|
476
|
+
# Write some output
|
477
|
+
worksheet1.write(0, 0, "Ciao", format1a)
|
478
|
+
worksheet1.write(1, 0, "Ciao", format1b)
|
479
|
+
|
480
|
+
worksheet2.write(0, 0, "Hello", format2a)
|
481
|
+
worksheet2.write(1, 0, "Hello", format2b)
|
482
|
+
workbook1.close
|
483
|
+
workbook2.close
|
484
|
+
|
485
|
+
# do assertion
|
486
|
+
compare_file("#{PERL_OUTDIR}/workbook1.xls", @filename)
|
487
|
+
compare_file("#{PERL_OUTDIR}/workbook2.xls", @filename2)
|
488
|
+
end
|
489
|
+
|
490
|
+
def test_data_validate
|
491
|
+
workbook = WriteExcel.new(@filename)
|
492
|
+
worksheet = workbook.add_worksheet
|
493
|
+
|
494
|
+
# Add a format for the header cells.
|
495
|
+
header_format = workbook.add_format(
|
496
|
+
:border => 1,
|
497
|
+
:bg_color => 43,
|
498
|
+
:bold => 1,
|
499
|
+
:text_wrap => 1,
|
500
|
+
:valign => 'vcenter',
|
501
|
+
:indent => 1
|
502
|
+
)
|
503
|
+
|
504
|
+
# Set up layout of the worksheet.
|
505
|
+
worksheet.set_column('A:A', 64)
|
506
|
+
worksheet.set_column('B:B', 15)
|
507
|
+
worksheet.set_column('D:D', 15)
|
508
|
+
worksheet.set_row(0, 36)
|
509
|
+
worksheet.set_selection('B3')
|
510
|
+
|
511
|
+
|
512
|
+
# Write the header cells and some data that will be used in the examples.
|
513
|
+
row = 0
|
514
|
+
heading1 = 'Some examples of data validation in WriteExcel'
|
515
|
+
heading2 = 'Enter values in this column'
|
516
|
+
heading3 = 'Sample Data'
|
517
|
+
|
518
|
+
worksheet.write('A1', heading1, header_format)
|
519
|
+
worksheet.write('B1', heading2, header_format)
|
520
|
+
worksheet.write('D1', heading3, header_format)
|
521
|
+
|
522
|
+
worksheet.write('D3', ['Integers', 1, 10])
|
523
|
+
worksheet.write('D4', ['List data', 'open', 'high', 'close'])
|
524
|
+
worksheet.write('D5', ['Formula', '=AND(F5=50,G5=60)', 50, 60])
|
525
|
+
|
526
|
+
|
527
|
+
#
|
528
|
+
# Example 1. Limiting input to an integer in a fixed range.
|
529
|
+
#
|
530
|
+
txt = 'Enter an integer between 1 and 10'
|
531
|
+
row += 2
|
532
|
+
|
533
|
+
worksheet.write(row, 0, txt)
|
534
|
+
worksheet.data_validation(row, 1,
|
535
|
+
{
|
536
|
+
:validate => 'integer',
|
537
|
+
:criteria => 'between',
|
538
|
+
:minimum => 1,
|
539
|
+
:maximum => 10
|
540
|
+
})
|
541
|
+
|
542
|
+
|
543
|
+
#
|
544
|
+
# Example 2. Limiting input to an integer outside a fixed range.
|
545
|
+
#
|
546
|
+
txt = 'Enter an integer that is not between 1 and 10 (using cell references)'
|
547
|
+
row += 2
|
548
|
+
|
549
|
+
worksheet.write(row, 0, txt)
|
550
|
+
worksheet.data_validation(row, 1,
|
551
|
+
{
|
552
|
+
:validate => 'integer',
|
553
|
+
:criteria => 'not between',
|
554
|
+
:minimum => '=E3',
|
555
|
+
:maximum => '=F3'
|
556
|
+
})
|
557
|
+
|
558
|
+
|
559
|
+
#
|
560
|
+
# Example 3. Limiting input to an integer greater than a fixed value.
|
561
|
+
#
|
562
|
+
txt = 'Enter an integer greater than 0'
|
563
|
+
row += 2
|
564
|
+
|
565
|
+
worksheet.write(row, 0, txt)
|
566
|
+
worksheet.data_validation(row, 1,
|
567
|
+
{
|
568
|
+
:validate => 'integer',
|
569
|
+
:criteria => '>',
|
570
|
+
:value => 0
|
571
|
+
})
|
572
|
+
|
573
|
+
|
574
|
+
#
|
575
|
+
# Example 4. Limiting input to an integer less than a fixed value.
|
576
|
+
#
|
577
|
+
txt = 'Enter an integer less than 10'
|
578
|
+
row += 2
|
579
|
+
|
580
|
+
worksheet.write(row, 0, txt)
|
581
|
+
worksheet.data_validation(row, 1,
|
582
|
+
{
|
583
|
+
:validate => 'integer',
|
584
|
+
:criteria => '<',
|
585
|
+
:value => 10
|
586
|
+
})
|
587
|
+
|
588
|
+
|
589
|
+
#
|
590
|
+
# Example 5. Limiting input to a decimal in a fixed range.
|
591
|
+
#
|
592
|
+
txt = 'Enter a decimal between 0.1 and 0.5'
|
593
|
+
row += 2
|
594
|
+
|
595
|
+
worksheet.write(row, 0, txt)
|
596
|
+
worksheet.data_validation(row, 1,
|
597
|
+
{
|
598
|
+
:validate => 'decimal',
|
599
|
+
:criteria => 'between',
|
600
|
+
:minimum => 0.1,
|
601
|
+
:maximum => 0.5
|
602
|
+
})
|
603
|
+
|
604
|
+
|
605
|
+
#
|
606
|
+
# Example 6. Limiting input to a value in a dropdown list.
|
607
|
+
#
|
608
|
+
txt = 'Select a value from a drop down list'
|
609
|
+
row += 2
|
610
|
+
bp=1
|
611
|
+
worksheet.write(row, 0, txt)
|
612
|
+
worksheet.data_validation(row, 1,
|
613
|
+
{
|
614
|
+
:validate => 'list',
|
615
|
+
:source => ['open', 'high', 'close']
|
616
|
+
})
|
617
|
+
|
618
|
+
|
619
|
+
#
|
620
|
+
# Example 6. Limiting input to a value in a dropdown list.
|
621
|
+
#
|
622
|
+
txt = 'Select a value from a drop down list (using a cell range)'
|
623
|
+
row += 2
|
624
|
+
|
625
|
+
worksheet.write(row, 0, txt)
|
626
|
+
worksheet.data_validation(row, 1,
|
627
|
+
{
|
628
|
+
:validate => 'list',
|
629
|
+
:source => '=E4:G4'
|
630
|
+
})
|
631
|
+
|
632
|
+
|
633
|
+
#
|
634
|
+
# Example 7. Limiting input to a date in a fixed range.
|
635
|
+
#
|
636
|
+
txt = 'Enter a date between 1/1/2008 and 12/12/2008'
|
637
|
+
row += 2
|
638
|
+
|
639
|
+
worksheet.write(row, 0, txt)
|
640
|
+
worksheet.data_validation(row, 1,
|
641
|
+
{
|
642
|
+
:validate => 'date',
|
643
|
+
:criteria => 'between',
|
644
|
+
:minimum => '2008-01-01T',
|
645
|
+
:maximum => '2008-12-12T'
|
646
|
+
})
|
647
|
+
|
648
|
+
|
649
|
+
#
|
650
|
+
# Example 8. Limiting input to a time in a fixed range.
|
651
|
+
#
|
652
|
+
txt = 'Enter a time between 6:00 and 12:00'
|
653
|
+
row += 2
|
654
|
+
|
655
|
+
worksheet.write(row, 0, txt)
|
656
|
+
worksheet.data_validation(row, 1,
|
657
|
+
{
|
658
|
+
:validate => 'time',
|
659
|
+
:criteria => 'between',
|
660
|
+
:minimum => 'T06:00',
|
661
|
+
:maximum => 'T12:00'
|
662
|
+
})
|
663
|
+
|
664
|
+
|
665
|
+
#
|
666
|
+
# Example 9. Limiting input to a string greater than a fixed length.
|
667
|
+
#
|
668
|
+
txt = 'Enter a string longer than 3 characters'
|
669
|
+
row += 2
|
670
|
+
|
671
|
+
worksheet.write(row, 0, txt)
|
672
|
+
worksheet.data_validation(row, 1,
|
673
|
+
{
|
674
|
+
:validate => 'length',
|
675
|
+
:criteria => '>',
|
676
|
+
:value => 3
|
677
|
+
})
|
678
|
+
|
679
|
+
|
680
|
+
#
|
681
|
+
# Example 10. Limiting input based on a formula.
|
682
|
+
#
|
683
|
+
txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"'
|
684
|
+
row += 2
|
685
|
+
|
686
|
+
worksheet.write(row, 0, txt)
|
687
|
+
worksheet.data_validation(row, 1,
|
688
|
+
{
|
689
|
+
:validate => 'custom',
|
690
|
+
:value => '=AND(F5=50,G5=60)'
|
691
|
+
})
|
692
|
+
|
693
|
+
|
694
|
+
#
|
695
|
+
# Example 11. Displaying and modify data validation messages.
|
696
|
+
#
|
697
|
+
txt = 'Displays a message when you select the cell'
|
698
|
+
row += 2
|
699
|
+
|
700
|
+
worksheet.write(row, 0, txt)
|
701
|
+
worksheet.data_validation(row, 1,
|
702
|
+
{
|
703
|
+
:validate => 'integer',
|
704
|
+
:criteria => 'between',
|
705
|
+
:minimum => 1,
|
706
|
+
:maximum => 100,
|
707
|
+
:input_title => 'Enter an integer:',
|
708
|
+
:input_message => 'between 1 and 100'
|
709
|
+
})
|
710
|
+
|
711
|
+
|
712
|
+
#
|
713
|
+
# Example 12. Displaying and modify data validation messages.
|
714
|
+
#
|
715
|
+
txt = 'Display a custom error message when integer isn\'t between 1 and 100'
|
716
|
+
row += 2
|
717
|
+
|
718
|
+
worksheet.write(row, 0, txt)
|
719
|
+
worksheet.data_validation(row, 1,
|
720
|
+
{
|
721
|
+
:validate => 'integer',
|
722
|
+
:criteria => 'between',
|
723
|
+
:minimum => 1,
|
724
|
+
:maximum => 100,
|
725
|
+
:input_title => 'Enter an integer:',
|
726
|
+
:input_message => 'between 1 and 100',
|
727
|
+
:error_title => 'Input value is not valid!',
|
728
|
+
:error_message => 'It should be an integer between 1 and 100'
|
729
|
+
})
|
730
|
+
|
731
|
+
|
732
|
+
#
|
733
|
+
# Example 13. Displaying and modify data validation messages.
|
734
|
+
#
|
735
|
+
txt = 'Display a custom information message when integer isn\'t between 1 and 100'
|
736
|
+
row += 2
|
737
|
+
|
738
|
+
worksheet.write(row, 0, txt)
|
739
|
+
worksheet.data_validation(row, 1,
|
740
|
+
{
|
741
|
+
:validate => 'integer',
|
742
|
+
:criteria => 'between',
|
743
|
+
:minimum => 1,
|
744
|
+
:maximum => 100,
|
745
|
+
:input_title => 'Enter an integer:',
|
746
|
+
:input_message => 'between 1 and 100',
|
747
|
+
:error_title => 'Input value is not valid!',
|
748
|
+
:error_message => 'It should be an integer between 1 and 100',
|
749
|
+
:error_type => 'information'
|
750
|
+
})
|
751
|
+
|
752
|
+
workbook.close
|
753
|
+
|
754
|
+
# do assertion
|
755
|
+
compare_file("#{PERL_OUTDIR}/data_validate.xls", @filename)
|
756
|
+
end
|
757
|
+
|
758
|
+
def test_merge1
|
759
|
+
workbook = WriteExcel.new(@filename)
|
760
|
+
worksheet = workbook.add_worksheet
|
761
|
+
|
762
|
+
# Increase the cell size of the merged cells to highlight the formatting.
|
763
|
+
worksheet.set_column('B:D', 20)
|
764
|
+
worksheet.set_row(2, 30)
|
765
|
+
|
766
|
+
# Create a merge format
|
767
|
+
format = workbook.add_format(:center_across => 1)
|
768
|
+
|
769
|
+
# Only one cell should contain text, the others should be blank.
|
770
|
+
worksheet.write(2, 1, "Center across selection", format)
|
771
|
+
worksheet.write_blank(2, 2, format)
|
772
|
+
worksheet.write_blank(2, 3, format)
|
773
|
+
|
774
|
+
workbook.close
|
775
|
+
|
776
|
+
# do assertion
|
777
|
+
compare_file("#{PERL_OUTDIR}/merge1.xls", @filename)
|
778
|
+
end
|
779
|
+
|
780
|
+
def test_merge2
|
781
|
+
workbook = WriteExcel.new(@filename)
|
782
|
+
worksheet = workbook.add_worksheet
|
783
|
+
|
784
|
+
# Increase the cell size of the merged cells to highlight the formatting.
|
785
|
+
worksheet.set_column(1, 2, 30)
|
786
|
+
worksheet.set_row(2, 40)
|
787
|
+
|
788
|
+
# Create a merged format
|
789
|
+
format = workbook.add_format(
|
790
|
+
:center_across => 1,
|
791
|
+
:bold => 1,
|
792
|
+
:size => 15,
|
793
|
+
:pattern => 1,
|
794
|
+
:border => 6,
|
795
|
+
:color => 'white',
|
796
|
+
:fg_color => 'green',
|
797
|
+
:border_color => 'yellow',
|
798
|
+
:align => 'vcenter'
|
799
|
+
)
|
800
|
+
|
801
|
+
# Only one cell should contain text, the others should be blank.
|
802
|
+
worksheet.write(2, 1, "Center across selection", format)
|
803
|
+
worksheet.write_blank(2, 2, format)
|
804
|
+
workbook.close
|
805
|
+
|
806
|
+
# do assertion
|
807
|
+
compare_file("#{PERL_OUTDIR}/merge2.xls", @filename)
|
808
|
+
end
|
809
|
+
|
810
|
+
def test_merge3
|
811
|
+
workbook = WriteExcel.new(@filename)
|
812
|
+
worksheet = workbook.add_worksheet()
|
813
|
+
|
814
|
+
# Increase the cell size of the merged cells to highlight the formatting.
|
815
|
+
[1, 3,6,7].each { |row| worksheet.set_row(row, 30) }
|
816
|
+
worksheet.set_column('B:D', 20)
|
817
|
+
|
818
|
+
###############################################################################
|
819
|
+
#
|
820
|
+
# Example 1: Merge cells containing a hyperlink using write_url_range()
|
821
|
+
# and the standard Excel 5+ merge property.
|
822
|
+
#
|
823
|
+
format1 = workbook.add_format(
|
824
|
+
:center_across => 1,
|
825
|
+
:border => 1,
|
826
|
+
:underline => 1,
|
827
|
+
:color => 'blue'
|
828
|
+
)
|
829
|
+
|
830
|
+
# Write the cells to be merged
|
831
|
+
worksheet.write_url_range('B2:D2', 'http://www.perl.com', format1)
|
832
|
+
worksheet.write_blank('C2', format1)
|
833
|
+
worksheet.write_blank('D2', format1)
|
834
|
+
|
835
|
+
|
836
|
+
|
837
|
+
###############################################################################
|
838
|
+
#
|
839
|
+
# Example 2: Merge cells containing a hyperlink using merge_range().
|
840
|
+
#
|
841
|
+
format2 = workbook.add_format(
|
842
|
+
:border => 1,
|
843
|
+
:underline => 1,
|
844
|
+
:color => 'blue',
|
845
|
+
:align => 'center',
|
846
|
+
:valign => 'vcenter'
|
847
|
+
)
|
848
|
+
|
849
|
+
# Merge 3 cells
|
850
|
+
worksheet.merge_range('B4:D4', 'http://www.perl.com', format2)
|
851
|
+
|
852
|
+
|
853
|
+
# Merge 3 cells over two rows
|
854
|
+
worksheet.merge_range('B7:D8', 'http://www.perl.com', format2)
|
855
|
+
|
856
|
+
workbook.close
|
857
|
+
|
858
|
+
# do assertion
|
859
|
+
compare_file("#{PERL_OUTDIR}/merge3.xls", @filename)
|
860
|
+
end
|
861
|
+
|
862
|
+
def test_merge4
|
863
|
+
# Create a new workbook and add a worksheet
|
864
|
+
workbook = WriteExcel.new(@filename)
|
865
|
+
worksheet = workbook.add_worksheet
|
866
|
+
|
867
|
+
# Increase the cell size of the merged cells to highlight the formatting.
|
868
|
+
(1..11).each { |row| worksheet.set_row(row, 30) }
|
869
|
+
worksheet.set_column('B:D', 20)
|
870
|
+
|
871
|
+
###############################################################################
|
872
|
+
#
|
873
|
+
# Example 1: Text centered vertically and horizontally
|
874
|
+
#
|
875
|
+
format1 = workbook.add_format(
|
876
|
+
:border => 6,
|
877
|
+
:bold => 1,
|
878
|
+
:color => 'red',
|
879
|
+
:valign => 'vcenter',
|
880
|
+
:align => 'center'
|
881
|
+
)
|
882
|
+
|
883
|
+
worksheet.merge_range('B2:D3', 'Vertical and horizontal', format1)
|
884
|
+
|
885
|
+
|
886
|
+
###############################################################################
|
887
|
+
#
|
888
|
+
# Example 2: Text aligned to the top and left
|
889
|
+
#
|
890
|
+
format2 = workbook.add_format(
|
891
|
+
:border => 6,
|
892
|
+
:bold => 1,
|
893
|
+
:color => 'red',
|
894
|
+
:valign => 'top',
|
895
|
+
:align => 'left'
|
896
|
+
)
|
897
|
+
|
898
|
+
worksheet.merge_range('B5:D6', 'Aligned to the top and left', format2)
|
899
|
+
|
900
|
+
###############################################################################
|
901
|
+
#
|
902
|
+
# Example 3: Text aligned to the bottom and right
|
903
|
+
#
|
904
|
+
format3 = workbook.add_format(
|
905
|
+
:border => 6,
|
906
|
+
:bold => 1,
|
907
|
+
:color => 'red',
|
908
|
+
:valign => 'bottom',
|
909
|
+
:align => 'right'
|
910
|
+
)
|
911
|
+
|
912
|
+
worksheet.merge_range('B8:D9', 'Aligned to the bottom and right', format3)
|
913
|
+
|
914
|
+
###############################################################################
|
915
|
+
#
|
916
|
+
# Example 4: Text justified (i.e. wrapped) in the cell
|
917
|
+
#
|
918
|
+
format4 = workbook.add_format(
|
919
|
+
:border => 6,
|
920
|
+
:bold => 1,
|
921
|
+
:color => 'red',
|
922
|
+
:valign => 'top',
|
923
|
+
:align => 'justify'
|
924
|
+
)
|
925
|
+
|
926
|
+
worksheet.merge_range('B11:D12', 'Justified: '+'so on and '*18, format4)
|
927
|
+
|
928
|
+
workbook.close
|
929
|
+
|
930
|
+
# do assertion
|
931
|
+
compare_file("#{PERL_OUTDIR}/merge4.xls", @filename)
|
932
|
+
end
|
933
|
+
|
934
|
+
def test_merge5
|
935
|
+
# Create a new workbook and add a worksheet
|
936
|
+
workbook = WriteExcel.new(@filename)
|
937
|
+
worksheet = workbook.add_worksheet
|
938
|
+
|
939
|
+
|
940
|
+
# Increase the cell size of the merged cells to highlight the formatting.
|
941
|
+
(3..8).each { |col| worksheet.set_row(col, 36) }
|
942
|
+
[1, 3, 5].each { |n| worksheet.set_column(n, n, 15) }
|
943
|
+
|
944
|
+
|
945
|
+
###############################################################################
|
946
|
+
#
|
947
|
+
# Rotation 1, letters run from top to bottom
|
948
|
+
#
|
949
|
+
format1 = workbook.add_format(
|
950
|
+
:border => 6,
|
951
|
+
:bold => 1,
|
952
|
+
:color => 'red',
|
953
|
+
:valign => 'vcentre',
|
954
|
+
:align => 'centre',
|
955
|
+
:rotation => 270
|
956
|
+
)
|
957
|
+
|
958
|
+
|
959
|
+
worksheet.merge_range('B4:B9', 'Rotation 270', format1)
|
960
|
+
|
961
|
+
|
962
|
+
###############################################################################
|
963
|
+
#
|
964
|
+
# Rotation 2, 90° anticlockwise
|
965
|
+
#
|
966
|
+
format2 = workbook.add_format(
|
967
|
+
:border => 6,
|
968
|
+
:bold => 1,
|
969
|
+
:color => 'red',
|
970
|
+
:valign => 'vcentre',
|
971
|
+
:align => 'centre',
|
972
|
+
:rotation => 90
|
973
|
+
)
|
974
|
+
|
975
|
+
|
976
|
+
worksheet.merge_range('D4:D9', 'Rotation 90', format2)
|
977
|
+
|
978
|
+
|
979
|
+
|
980
|
+
###############################################################################
|
981
|
+
#
|
982
|
+
# Rotation 3, 90° clockwise
|
983
|
+
#
|
984
|
+
format3 = workbook.add_format(
|
985
|
+
:border => 6,
|
986
|
+
:bold => 1,
|
987
|
+
:color => 'red',
|
988
|
+
:valign => 'vcentre',
|
989
|
+
:align => 'centre',
|
990
|
+
:rotation => -90
|
991
|
+
)
|
992
|
+
|
993
|
+
|
994
|
+
worksheet.merge_range('F4:F9', 'Rotation -90', format3)
|
995
|
+
|
996
|
+
workbook.close
|
997
|
+
|
998
|
+
# do assertion
|
999
|
+
compare_file("#{PERL_OUTDIR}/merge5.xls", @filename)
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
def test_images
|
1003
|
+
# Create a new workbook called simple.xls and add a worksheet
|
1004
|
+
workbook = WriteExcel.new(@filename)
|
1005
|
+
worksheet1 = workbook.add_worksheet('Image 1')
|
1006
|
+
worksheet2 = workbook.add_worksheet('Image 2')
|
1007
|
+
worksheet3 = workbook.add_worksheet('Image 3')
|
1008
|
+
worksheet4 = workbook.add_worksheet('Image 4')
|
1009
|
+
bp=1
|
1010
|
+
|
1011
|
+
# Insert a basic image
|
1012
|
+
worksheet1.write('A10', "Image inserted into worksheet.")
|
1013
|
+
worksheet1.insert_image('A1', File.join(TEST_DIR,'republic.png'))
|
1014
|
+
|
1015
|
+
|
1016
|
+
# Insert an image with an offset
|
1017
|
+
worksheet2.write('A10', "Image inserted with an offset.")
|
1018
|
+
worksheet2.insert_image('A1', File.join(TEST_DIR,'republic.png'), 32, 10)
|
1019
|
+
|
1020
|
+
# Insert a scaled image
|
1021
|
+
worksheet3.write('A10', "Image scaled: width x 2, height x 0.8.")
|
1022
|
+
worksheet3.insert_image('A1', File.join(TEST_DIR,'republic.png'), 0, 0, 2, 0.8)
|
1023
|
+
|
1024
|
+
# Insert an image over varied column and row sizes
|
1025
|
+
# This does not require any additional work
|
1026
|
+
|
1027
|
+
# Set the cols and row sizes
|
1028
|
+
# NOTE: you must do this before you call insert_image()
|
1029
|
+
worksheet4.set_column('A:A', 5)
|
1030
|
+
worksheet4.set_column('B:B', nil, nil, 1) # Hidden
|
1031
|
+
worksheet4.set_column('C:D', 10)
|
1032
|
+
worksheet4.set_row(0, 30)
|
1033
|
+
worksheet4.set_row(3, 5)
|
1034
|
+
|
1035
|
+
worksheet4.write('A10', "Image inserted over scaled rows and columns.")
|
1036
|
+
worksheet4.insert_image('A1', File.join(TEST_DIR,'republic.png'))
|
1037
|
+
|
1038
|
+
workbook.close
|
1039
|
+
|
1040
|
+
# do assertion
|
1041
|
+
compare_file("#{PERL_OUTDIR}/images.xls", @filename)
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
def test_tab_colors
|
1045
|
+
workbook = WriteExcel.new(@filename)
|
1046
|
+
|
1047
|
+
worksheet1 = workbook.add_worksheet
|
1048
|
+
worksheet2 = workbook.add_worksheet
|
1049
|
+
worksheet3 = workbook.add_worksheet
|
1050
|
+
worksheet4 = workbook.add_worksheet
|
1051
|
+
|
1052
|
+
# Worsheet1 will have the default tab colour.
|
1053
|
+
worksheet2.set_tab_color('red')
|
1054
|
+
worksheet3.set_tab_color('green')
|
1055
|
+
worksheet4.set_tab_color(0x35) # Orange
|
1056
|
+
|
1057
|
+
workbook.close
|
1058
|
+
|
1059
|
+
# do assertion
|
1060
|
+
compare_file("#{PERL_OUTDIR}/tab_colors.xls", @filename)
|
1061
|
+
end
|
1062
|
+
|
1063
|
+
def test_stocks
|
1064
|
+
# Create a new workbook and add a worksheet
|
1065
|
+
workbook = WriteExcel.new(@filename)
|
1066
|
+
worksheet = workbook.add_worksheet
|
1067
|
+
|
1068
|
+
# Set the column width for columns 1, 2, 3 and 4
|
1069
|
+
worksheet.set_column(0, 3, 15)
|
1070
|
+
|
1071
|
+
|
1072
|
+
# Create a format for the column headings
|
1073
|
+
header = workbook.add_format
|
1074
|
+
header.set_bold
|
1075
|
+
header.set_size(12)
|
1076
|
+
header.set_color('blue')
|
1077
|
+
|
1078
|
+
|
1079
|
+
# Create a format for the stock price
|
1080
|
+
f_price = workbook.add_format
|
1081
|
+
f_price.set_align('left')
|
1082
|
+
f_price.set_num_format('$0.00')
|
1083
|
+
|
1084
|
+
|
1085
|
+
# Create a format for the stock volume
|
1086
|
+
f_volume = workbook.add_format
|
1087
|
+
f_volume.set_align('left')
|
1088
|
+
f_volume.set_num_format('#,##0')
|
1089
|
+
|
1090
|
+
|
1091
|
+
# Create a format for the price change. This is an example of a conditional
|
1092
|
+
# format. The number is formatted as a percentage. If it is positive it is
|
1093
|
+
# formatted in green, if it is negative it is formatted in red and if it is
|
1094
|
+
# zero it is formatted as the default font colour (in this case black).
|
1095
|
+
# Note: the [Green] format produces an unappealing lime green. Try
|
1096
|
+
# [Color 10] instead for a dark green.
|
1097
|
+
#
|
1098
|
+
f_change = workbook.add_format
|
1099
|
+
f_change.set_align('left')
|
1100
|
+
f_change.set_num_format('[Green]0.0%;[Red]-0.0%;0.0%')
|
1101
|
+
|
1102
|
+
|
1103
|
+
# Write out the data
|
1104
|
+
worksheet.write(0, 0, 'Company', header)
|
1105
|
+
worksheet.write(0, 1, 'Price', header)
|
1106
|
+
worksheet.write(0, 2, 'Volume', header)
|
1107
|
+
worksheet.write(0, 3, 'Change', header)
|
1108
|
+
|
1109
|
+
worksheet.write(1, 0, 'Damage Inc.' )
|
1110
|
+
worksheet.write(1, 1, 30.25, f_price) # $30.25
|
1111
|
+
worksheet.write(1, 2, 1234567, f_volume) # 1,234,567
|
1112
|
+
worksheet.write(1, 3, 0.085, f_change) # 8.5% in green
|
1113
|
+
|
1114
|
+
worksheet.write(2, 0, 'Dump Corp.' )
|
1115
|
+
worksheet.write(2, 1, 1.56, f_price) # $1.56
|
1116
|
+
worksheet.write(2, 2, 7564, f_volume) # 7,564
|
1117
|
+
worksheet.write(2, 3, -0.015, f_change) # -1.5% in red
|
1118
|
+
|
1119
|
+
worksheet.write(3, 0, 'Rev Ltd.' )
|
1120
|
+
worksheet.write(3, 1, 0.13, f_price) # $0.13
|
1121
|
+
worksheet.write(3, 2, 321, f_volume) # 321
|
1122
|
+
worksheet.write(3, 3, 0, f_change) # 0 in the font color (black)
|
1123
|
+
|
1124
|
+
workbook.close
|
1125
|
+
|
1126
|
+
# do assertion
|
1127
|
+
compare_file("#{PERL_OUTDIR}/stocks.xls", @filename)
|
1128
|
+
end
|
1129
|
+
|
1130
|
+
def test_protection
|
1131
|
+
workbook = WriteExcel.new(@filename)
|
1132
|
+
worksheet = workbook.add_worksheet
|
1133
|
+
|
1134
|
+
# Create some format objects
|
1135
|
+
locked = workbook.add_format(:locked => 1)
|
1136
|
+
unlocked = workbook.add_format(:locked => 0)
|
1137
|
+
hidden = workbook.add_format(:hidden => 1)
|
1138
|
+
|
1139
|
+
# Format the columns
|
1140
|
+
worksheet.set_column('A:A', 42)
|
1141
|
+
worksheet.set_selection('B3:B3')
|
1142
|
+
|
1143
|
+
# Protect the worksheet
|
1144
|
+
worksheet.protect
|
1145
|
+
|
1146
|
+
# Examples of cell locking and hiding
|
1147
|
+
worksheet.write('A1', 'Cell B1 is locked. It cannot be edited.')
|
1148
|
+
worksheet.write('B1', '=1+2', locked)
|
1149
|
+
|
1150
|
+
worksheet.write('A2', 'Cell B2 is unlocked. It can be edited.')
|
1151
|
+
worksheet.write('B2', '=1+2', unlocked)
|
1152
|
+
|
1153
|
+
worksheet.write('A3', "Cell B3 is hidden. The formula isn't visible.")
|
1154
|
+
worksheet.write('B3', '=1+2', hidden)
|
1155
|
+
|
1156
|
+
worksheet.write('A5', 'Use Menu->Tools->Protection->Unprotect Sheet')
|
1157
|
+
worksheet.write('A6', 'to remove the worksheet protection. ')
|
1158
|
+
|
1159
|
+
workbook.close
|
1160
|
+
|
1161
|
+
# do assertion
|
1162
|
+
compare_file("#{PERL_OUTDIR}/protection.xls", @filename)
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
def test_date_time
|
1166
|
+
# Create a new workbook and add a worksheet
|
1167
|
+
workbook = WriteExcel.new(@filename)
|
1168
|
+
worksheet = workbook.add_worksheet
|
1169
|
+
bold = workbook.add_format(:bold => 1)
|
1170
|
+
|
1171
|
+
# Expand the first column so that the date is visible.
|
1172
|
+
worksheet.set_column("A:B", 30)
|
1173
|
+
|
1174
|
+
# Write the column headers
|
1175
|
+
worksheet.write('A1', 'Formatted date', bold)
|
1176
|
+
worksheet.write('B1', 'Format', bold)
|
1177
|
+
|
1178
|
+
# Examples date and time formats. In the output file compare how changing
|
1179
|
+
# the format codes change the appearance of the date.
|
1180
|
+
#
|
1181
|
+
date_formats = [
|
1182
|
+
'dd/mm/yy',
|
1183
|
+
'mm/dd/yy',
|
1184
|
+
'',
|
1185
|
+
'd mm yy',
|
1186
|
+
'dd mm yy',
|
1187
|
+
'',
|
1188
|
+
'dd m yy',
|
1189
|
+
'dd mm yy',
|
1190
|
+
'dd mmm yy',
|
1191
|
+
'dd mmmm yy',
|
1192
|
+
'',
|
1193
|
+
'dd mm y',
|
1194
|
+
'dd mm yyy',
|
1195
|
+
'dd mm yyyy',
|
1196
|
+
'',
|
1197
|
+
'd mmmm yyyy',
|
1198
|
+
'',
|
1199
|
+
'dd/mm/yy',
|
1200
|
+
'dd/mm/yy hh:mm',
|
1201
|
+
'dd/mm/yy hh:mm:ss',
|
1202
|
+
'dd/mm/yy hh:mm:ss.000',
|
1203
|
+
'',
|
1204
|
+
'hh:mm',
|
1205
|
+
'hh:mm:ss',
|
1206
|
+
'hh:mm:ss.000',
|
1207
|
+
]
|
1208
|
+
|
1209
|
+
# Write the same date and time using each of the above formats. The empty
|
1210
|
+
# string formats create a blank line to make the example clearer.
|
1211
|
+
#
|
1212
|
+
row = 0
|
1213
|
+
date_formats.each do |date_format|
|
1214
|
+
row += 1
|
1215
|
+
next if date_format == ''
|
1216
|
+
|
1217
|
+
# Create a format for the date or time.
|
1218
|
+
format = workbook.add_format(
|
1219
|
+
:num_format => date_format,
|
1220
|
+
:align => 'left'
|
1221
|
+
)
|
1222
|
+
|
1223
|
+
# Write the same date using different formats.
|
1224
|
+
worksheet.write_date_time(row, 0, '2004-08-01T12:30:45.123', format)
|
1225
|
+
worksheet.write(row, 1, date_format)
|
1226
|
+
end
|
1227
|
+
|
1228
|
+
# The following is an example of an invalid date. It is written as a string instead
|
1229
|
+
# of a number. This is also Excel's default behaviour.
|
1230
|
+
#
|
1231
|
+
row += 2
|
1232
|
+
worksheet.write_date_time(row, 0, '2004-13-01T12:30:45.123')
|
1233
|
+
worksheet.write(row, 1, 'Invalid date. Written as string.', bold)
|
1234
|
+
|
1235
|
+
workbook.close
|
1236
|
+
|
1237
|
+
# do assertion
|
1238
|
+
compare_file("#{PERL_OUTDIR}/date_time.xls", @filename)
|
1239
|
+
end
|
1240
|
+
|
1241
|
+
def test_diag_border
|
1242
|
+
workbook = WriteExcel.new(@filename)
|
1243
|
+
worksheet = workbook.add_worksheet
|
1244
|
+
|
1245
|
+
format1 = workbook.add_format(:diag_type => 1)
|
1246
|
+
format2 = workbook.add_format(:diag_type => 2)
|
1247
|
+
format3 = workbook.add_format(:diag_type => 3)
|
1248
|
+
format4 = workbook.add_format(
|
1249
|
+
:diag_type => 3,
|
1250
|
+
:diag_border => 7,
|
1251
|
+
:diag_color => 'red'
|
1252
|
+
)
|
1253
|
+
|
1254
|
+
worksheet.write('B3', 'Text', format1)
|
1255
|
+
worksheet.write('B6', 'Text', format2)
|
1256
|
+
worksheet.write('B9', 'Text', format3)
|
1257
|
+
worksheet.write('B12', 'Text', format4)
|
1258
|
+
|
1259
|
+
workbook.close
|
1260
|
+
|
1261
|
+
# do assertion
|
1262
|
+
compare_file("#{PERL_OUTDIR}/diag_border.xls", @filename)
|
1263
|
+
end
|
1264
|
+
|
1265
|
+
def test_headers
|
1266
|
+
workbook = WriteExcel.new(@filename)
|
1267
|
+
preview = "Select Print Preview to see the header and footer"
|
1268
|
+
|
1269
|
+
|
1270
|
+
######################################################################
|
1271
|
+
#
|
1272
|
+
# A simple example to start
|
1273
|
+
#
|
1274
|
+
worksheet1 = workbook.add_worksheet('Simple')
|
1275
|
+
|
1276
|
+
header1 = '&CHere is some centred text.'
|
1277
|
+
|
1278
|
+
footer1 = '&LHere is some left aligned text.'
|
1279
|
+
|
1280
|
+
|
1281
|
+
worksheet1.set_header(header1)
|
1282
|
+
worksheet1.set_footer(footer1)
|
1283
|
+
|
1284
|
+
worksheet1.set_column('A:A', 50)
|
1285
|
+
worksheet1.write('A1', preview)
|
1286
|
+
|
1287
|
+
|
1288
|
+
######################################################################
|
1289
|
+
#
|
1290
|
+
# This is an example of some of the header/footer variables.
|
1291
|
+
#
|
1292
|
+
worksheet2 = workbook.add_worksheet('Variables')
|
1293
|
+
|
1294
|
+
header2 = '&LPage &P of &N'+
|
1295
|
+
'&CFilename: &F' +
|
1296
|
+
'&RSheetname: &A'
|
1297
|
+
|
1298
|
+
footer2 = '&LCurrent date: &D'+
|
1299
|
+
'&RCurrent time: &T'
|
1300
|
+
|
1301
|
+
worksheet2.set_header(header2)
|
1302
|
+
worksheet2.set_footer(footer2)
|
1303
|
+
|
1304
|
+
|
1305
|
+
worksheet2.set_column('A:A', 50)
|
1306
|
+
worksheet2.write('A1', preview)
|
1307
|
+
worksheet2.write('A21', "Next sheet")
|
1308
|
+
worksheet2.set_h_pagebreaks(20)
|
1309
|
+
|
1310
|
+
|
1311
|
+
######################################################################
|
1312
|
+
#
|
1313
|
+
# This example shows how to use more than one font
|
1314
|
+
#
|
1315
|
+
worksheet3 = workbook.add_worksheet('Mixed fonts')
|
1316
|
+
|
1317
|
+
header3 = '&C' +
|
1318
|
+
'&"Courier New,Bold"Hello ' +
|
1319
|
+
'&"Arial,Italic"World'
|
1320
|
+
|
1321
|
+
footer3 = '&C' +
|
1322
|
+
'&"Symbol"e' +
|
1323
|
+
'&"Arial" = mc&X2'
|
1324
|
+
|
1325
|
+
worksheet3.set_header(header3)
|
1326
|
+
worksheet3.set_footer(footer3)
|
1327
|
+
|
1328
|
+
worksheet3.set_column('A:A', 50)
|
1329
|
+
worksheet3.write('A1', preview)
|
1330
|
+
|
1331
|
+
|
1332
|
+
######################################################################
|
1333
|
+
#
|
1334
|
+
# Example of line wrapping
|
1335
|
+
#
|
1336
|
+
worksheet4 = workbook.add_worksheet('Word wrap')
|
1337
|
+
|
1338
|
+
header4 = "&CHeading 1\nHeading 2\nHeading 3"
|
1339
|
+
|
1340
|
+
worksheet4.set_header(header4)
|
1341
|
+
|
1342
|
+
worksheet4.set_column('A:A', 50)
|
1343
|
+
worksheet4.write('A1', preview)
|
1344
|
+
|
1345
|
+
|
1346
|
+
######################################################################
|
1347
|
+
#
|
1348
|
+
# Example of inserting a literal ampersand &
|
1349
|
+
#
|
1350
|
+
worksheet5 = workbook.add_worksheet('Ampersand')
|
1351
|
+
|
1352
|
+
header5 = "&CCuriouser && Curiouser - Attorneys at Law"
|
1353
|
+
|
1354
|
+
worksheet5.set_header(header5)
|
1355
|
+
|
1356
|
+
worksheet5.set_column('A:A', 50)
|
1357
|
+
worksheet5.write('A1', preview)
|
1358
|
+
|
1359
|
+
workbook.close
|
1360
|
+
|
1361
|
+
# do assertion
|
1362
|
+
compare_file("#{PERL_OUTDIR}/headers.xls", @filename)
|
1363
|
+
end
|
1364
|
+
|
1365
|
+
def test_demo
|
1366
|
+
workbook = WriteExcel.new(@filename)
|
1367
|
+
worksheet = workbook.add_worksheet('Demo')
|
1368
|
+
worksheet2 = workbook.add_worksheet('Another sheet')
|
1369
|
+
worksheet3 = workbook.add_worksheet('And another')
|
1370
|
+
|
1371
|
+
bold = workbook.add_format(:bold => 1)
|
1372
|
+
|
1373
|
+
#######################################################################
|
1374
|
+
#
|
1375
|
+
# Write a general heading
|
1376
|
+
#
|
1377
|
+
worksheet.set_column('A:A', 36, bold)
|
1378
|
+
worksheet.set_column('B:B', 20 )
|
1379
|
+
worksheet.set_row(0, 40 )
|
1380
|
+
|
1381
|
+
heading = workbook.add_format(
|
1382
|
+
:bold => 1,
|
1383
|
+
:color => 'blue',
|
1384
|
+
:size => 16,
|
1385
|
+
:merge => 1,
|
1386
|
+
:align => 'vcenter'
|
1387
|
+
)
|
1388
|
+
|
1389
|
+
headings = ['Features of Spreadsheet::WriteExcel', '']
|
1390
|
+
worksheet.write_row('A1', headings, heading)
|
1391
|
+
|
1392
|
+
|
1393
|
+
#######################################################################
|
1394
|
+
#
|
1395
|
+
# Some text examples
|
1396
|
+
#
|
1397
|
+
text_format = workbook.add_format(
|
1398
|
+
:bold => 1,
|
1399
|
+
:italic => 1,
|
1400
|
+
:color => 'red',
|
1401
|
+
:size => 18,
|
1402
|
+
:font =>'Lucida Calligraphy'
|
1403
|
+
)
|
1404
|
+
|
1405
|
+
# A phrase in Cyrillic
|
1406
|
+
unicode = [
|
1407
|
+
"042d0442043e002004440440043004370430002004"+
|
1408
|
+
"3d043000200440044304410441043a043e043c0021"
|
1409
|
+
].pack('H*')
|
1410
|
+
|
1411
|
+
worksheet.write('A2', "Text")
|
1412
|
+
worksheet.write('B2', "Hello Excel")
|
1413
|
+
worksheet.write('A3', "Formatted text")
|
1414
|
+
worksheet.write('B3', "Hello Excel", text_format)
|
1415
|
+
worksheet.write('A4', "Unicode text")
|
1416
|
+
worksheet.write_utf16be_string('B4', unicode)
|
1417
|
+
|
1418
|
+
|
1419
|
+
#######################################################################
|
1420
|
+
#
|
1421
|
+
# Some numeric examples
|
1422
|
+
#
|
1423
|
+
num1_format = workbook.add_format(:num_format => '$#,##0.00')
|
1424
|
+
num2_format = workbook.add_format(:num_format => ' d mmmm yyy')
|
1425
|
+
|
1426
|
+
worksheet.write('A5', "Numbers")
|
1427
|
+
worksheet.write('B5', 1234.56)
|
1428
|
+
worksheet.write('A6', "Formatted numbers")
|
1429
|
+
worksheet.write('B6', 1234.56, num1_format)
|
1430
|
+
worksheet.write('A7', "Formatted numbers")
|
1431
|
+
worksheet.write('B7', 37257, num2_format)
|
1432
|
+
|
1433
|
+
|
1434
|
+
#######################################################################
|
1435
|
+
#
|
1436
|
+
# Formulae
|
1437
|
+
#
|
1438
|
+
worksheet.set_selection('B8')
|
1439
|
+
worksheet.write('A8', 'Formulas and functions, "=SIN(PI()/4)"')
|
1440
|
+
worksheet.write('B8', '=SIN(PI()/4)')
|
1441
|
+
|
1442
|
+
|
1443
|
+
#######################################################################
|
1444
|
+
#
|
1445
|
+
# Hyperlinks
|
1446
|
+
#
|
1447
|
+
worksheet.write('A9', "Hyperlinks")
|
1448
|
+
worksheet.write('B9', 'http://www.perl.com/' )
|
1449
|
+
|
1450
|
+
|
1451
|
+
#######################################################################
|
1452
|
+
#
|
1453
|
+
# Images
|
1454
|
+
#
|
1455
|
+
worksheet.write('A10', "Images")
|
1456
|
+
worksheet.insert_image('B10', 'republic.png', 16, 8)
|
1457
|
+
|
1458
|
+
|
1459
|
+
#######################################################################
|
1460
|
+
#
|
1461
|
+
# Misc
|
1462
|
+
#
|
1463
|
+
worksheet.write('A18', "Page/printer setup")
|
1464
|
+
worksheet.write('A19', "Multiple worksheets")
|
1465
|
+
|
1466
|
+
workbook.close
|
1467
|
+
|
1468
|
+
# do assertion
|
1469
|
+
compare_file("#{PERL_OUTDIR}/demo.xls", @filename)
|
1470
|
+
end
|
1471
|
+
|
1472
|
+
def test_unicode_cyrillic
|
1473
|
+
# Create a Russian worksheet name in utf8.
|
1474
|
+
sheet = [0x0421, 0x0442, 0x0440, 0x0430, 0x043D, 0x0438,
|
1475
|
+
0x0446, 0x0430].pack("U*")
|
1476
|
+
|
1477
|
+
# Create a Russian string.
|
1478
|
+
str = [0x0417, 0x0434, 0x0440, 0x0430, 0x0432, 0x0441,
|
1479
|
+
0x0442, 0x0432, 0x0443, 0x0439, 0x0020, 0x041C,
|
1480
|
+
0x0438, 0x0440, 0x0021].pack("U*")
|
1481
|
+
|
1482
|
+
workbook = WriteExcel.new(@filename)
|
1483
|
+
worksheet = workbook.add_worksheet(sheet + '1')
|
1484
|
+
|
1485
|
+
worksheet.set_column('A:A', 18)
|
1486
|
+
worksheet.write('A1', str)
|
1487
|
+
|
1488
|
+
workbook.close
|
1489
|
+
|
1490
|
+
# do assertion
|
1491
|
+
compare_file("#{PERL_OUTDIR}/unicode_cyrillic.xls", @filename)
|
1492
|
+
end
|
1493
|
+
|
1494
|
+
def test_chart_area
|
1495
|
+
workbook = WriteExcel.new(@filename)
|
1496
|
+
worksheet = workbook.add_worksheet
|
1497
|
+
bold = workbook.add_format(:bold => 1)
|
1498
|
+
|
1499
|
+
# Add the data to the worksheet that the charts will refer to.
|
1500
|
+
headings = [ 'Category', 'Values 1', 'Values 2' ]
|
1501
|
+
data = [
|
1502
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
1503
|
+
[ 1, 4, 5, 2, 1, 5 ],
|
1504
|
+
[ 3, 6, 7, 5, 4, 3 ]
|
1505
|
+
]
|
1506
|
+
|
1507
|
+
worksheet.write('A1', headings, bold)
|
1508
|
+
worksheet.write('A2', data)
|
1509
|
+
|
1510
|
+
|
1511
|
+
###############################################################################
|
1512
|
+
#
|
1513
|
+
# Example 1. A minimal chart.
|
1514
|
+
#
|
1515
|
+
chart1 = workbook.add_chart(:type => Chart::Area)
|
1516
|
+
|
1517
|
+
# Add values only. Use the default categories.
|
1518
|
+
chart1.add_series( :values => '=Sheet1!$B$2:$B$7' )
|
1519
|
+
|
1520
|
+
###############################################################################
|
1521
|
+
#
|
1522
|
+
# Example 2. A minimal chart with user specified categories (X axis)
|
1523
|
+
# and a series name.
|
1524
|
+
#
|
1525
|
+
chart2 = workbook.add_chart(:type => Chart::Area)
|
1526
|
+
|
1527
|
+
# Configure the series.
|
1528
|
+
chart2.add_series(
|
1529
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1530
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1531
|
+
:name => 'Test data series 1'
|
1532
|
+
)
|
1533
|
+
|
1534
|
+
###############################################################################
|
1535
|
+
#
|
1536
|
+
# Example 3. Same as previous chart but with added title and axes labels.
|
1537
|
+
#
|
1538
|
+
chart3 = workbook.add_chart(:type => Chart::Area)
|
1539
|
+
|
1540
|
+
# Configure the series.
|
1541
|
+
chart3.add_series(
|
1542
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1543
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1544
|
+
:name => 'Test data series 1'
|
1545
|
+
)
|
1546
|
+
|
1547
|
+
# Add some labels.
|
1548
|
+
chart3.set_title( :name => 'Results of sample analysis' )
|
1549
|
+
chart3.set_x_axis( :name => 'Sample number' )
|
1550
|
+
chart3.set_y_axis( :name => 'Sample length (cm)' )
|
1551
|
+
|
1552
|
+
###############################################################################
|
1553
|
+
#
|
1554
|
+
# Example 4. Same as previous chart but with an added series
|
1555
|
+
#
|
1556
|
+
chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Area)
|
1557
|
+
|
1558
|
+
# Configure the series.
|
1559
|
+
chart4.add_series(
|
1560
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1561
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1562
|
+
:name => 'Test data series 1'
|
1563
|
+
)
|
1564
|
+
|
1565
|
+
# Add another series.
|
1566
|
+
chart4.add_series(
|
1567
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1568
|
+
:values => '=Sheet1!$C$2:$C$7',
|
1569
|
+
:name => 'Test data series 2'
|
1570
|
+
)
|
1571
|
+
|
1572
|
+
# Add some labels.
|
1573
|
+
chart4.set_title( :name => 'Results of sample analysis' )
|
1574
|
+
chart4.set_x_axis( :name => 'Sample number' )
|
1575
|
+
chart4.set_y_axis( :name => 'Sample length (cm)' )
|
1576
|
+
|
1577
|
+
###############################################################################
|
1578
|
+
#
|
1579
|
+
# Example 5. Same as Example 3 but as an embedded chart.
|
1580
|
+
#
|
1581
|
+
chart5 = workbook.add_chart(:type => Chart::Area, :embedded => 1)
|
1582
|
+
|
1583
|
+
# Configure the series.
|
1584
|
+
chart5.add_series(
|
1585
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1586
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1587
|
+
:name => 'Test data series 1'
|
1588
|
+
)
|
1589
|
+
|
1590
|
+
# Add some labels.
|
1591
|
+
chart5.set_title(:name => 'Results of sample analysis' )
|
1592
|
+
chart5.set_x_axis(:name => 'Sample number')
|
1593
|
+
chart5.set_y_axis(:name => 'Sample length (cm)')
|
1594
|
+
|
1595
|
+
# Insert the chart into the main worksheet.
|
1596
|
+
worksheet.insert_chart('E2', chart5)
|
1597
|
+
|
1598
|
+
# File save
|
1599
|
+
workbook.close
|
1600
|
+
|
1601
|
+
# do assertion
|
1602
|
+
compare_file("#{PERL_OUTDIR}/chart_area.xls", @filename)
|
1603
|
+
end
|
1604
|
+
|
1605
|
+
def test_chart_bar
|
1606
|
+
workbook = WriteExcel.new(@filename)
|
1607
|
+
worksheet = workbook.add_worksheet
|
1608
|
+
bold = workbook.add_format(:bold => 1)
|
1609
|
+
|
1610
|
+
# Add the data to the worksheet that the charts will refer to.
|
1611
|
+
headings = [ 'Category', 'Values 1', 'Values 2' ]
|
1612
|
+
data = [
|
1613
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
1614
|
+
[ 1, 4, 5, 2, 1, 5 ],
|
1615
|
+
[ 3, 6, 7, 5, 4, 3 ]
|
1616
|
+
]
|
1617
|
+
|
1618
|
+
worksheet.write('A1', headings, bold)
|
1619
|
+
worksheet.write('A2', data)
|
1620
|
+
|
1621
|
+
|
1622
|
+
###############################################################################
|
1623
|
+
#
|
1624
|
+
# Example 1. A minimal chart.
|
1625
|
+
#
|
1626
|
+
chart1 = workbook.add_chart(:type => Chart::Bar)
|
1627
|
+
|
1628
|
+
# Add values only. Use the default categories.
|
1629
|
+
chart1.add_series( :values => '=Sheet1!$B$2:$B$7' )
|
1630
|
+
|
1631
|
+
###############################################################################
|
1632
|
+
#
|
1633
|
+
# Example 2. A minimal chart with user specified categories (X axis)
|
1634
|
+
# and a series name.
|
1635
|
+
#
|
1636
|
+
chart2 = workbook.add_chart(:type => Chart::Bar)
|
1637
|
+
|
1638
|
+
# Configure the series.
|
1639
|
+
chart2.add_series(
|
1640
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1641
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1642
|
+
:name => 'Test data series 1'
|
1643
|
+
)
|
1644
|
+
|
1645
|
+
###############################################################################
|
1646
|
+
#
|
1647
|
+
# Example 3. Same as previous chart but with added title and axes labels.
|
1648
|
+
#
|
1649
|
+
chart3 = workbook.add_chart(:type => Chart::Bar)
|
1650
|
+
|
1651
|
+
# Configure the series.
|
1652
|
+
chart3.add_series(
|
1653
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1654
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1655
|
+
:name => 'Test data series 1'
|
1656
|
+
)
|
1657
|
+
|
1658
|
+
# Add some labels.
|
1659
|
+
chart3.set_title( :name => 'Results of sample analysis' )
|
1660
|
+
chart3.set_x_axis( :name => 'Sample number' )
|
1661
|
+
chart3.set_y_axis( :name => 'Sample length (cm)' )
|
1662
|
+
|
1663
|
+
###############################################################################
|
1664
|
+
#
|
1665
|
+
# Example 4. Same as previous chart but with an added series
|
1666
|
+
#
|
1667
|
+
chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Bar)
|
1668
|
+
|
1669
|
+
# Configure the series.
|
1670
|
+
chart4.add_series(
|
1671
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1672
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1673
|
+
:name => 'Test data series 1'
|
1674
|
+
)
|
1675
|
+
|
1676
|
+
# Add another series.
|
1677
|
+
chart4.add_series(
|
1678
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1679
|
+
:values => '=Sheet1!$C$2:$C$7',
|
1680
|
+
:name => 'Test data series 2'
|
1681
|
+
)
|
1682
|
+
|
1683
|
+
# Add some labels.
|
1684
|
+
chart4.set_title( :name => 'Results of sample analysis' )
|
1685
|
+
chart4.set_x_axis( :name => 'Sample number' )
|
1686
|
+
chart4.set_y_axis( :name => 'Sample length (cm)' )
|
1687
|
+
|
1688
|
+
###############################################################################
|
1689
|
+
#
|
1690
|
+
# Example 5. Same as Example 3 but as an embedded chart.
|
1691
|
+
#
|
1692
|
+
chart5 = workbook.add_chart(:type => Chart::Bar, :embedded => 1)
|
1693
|
+
|
1694
|
+
# Configure the series.
|
1695
|
+
chart5.add_series(
|
1696
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1697
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1698
|
+
:name => 'Test data series 1'
|
1699
|
+
)
|
1700
|
+
|
1701
|
+
# Add some labels.
|
1702
|
+
chart5.set_title(:name => 'Results of sample analysis' )
|
1703
|
+
chart5.set_x_axis(:name => 'Sample number')
|
1704
|
+
chart5.set_y_axis(:name => 'Sample length (cm)')
|
1705
|
+
|
1706
|
+
# Insert the chart into the main worksheet.
|
1707
|
+
worksheet.insert_chart('E2', chart5)
|
1708
|
+
|
1709
|
+
# File save
|
1710
|
+
workbook.close
|
1711
|
+
|
1712
|
+
# do assertion
|
1713
|
+
compare_file("#{PERL_OUTDIR}/chart_bar.xls", @filename)
|
1714
|
+
end
|
1715
|
+
|
1716
|
+
def test_chart_column
|
1717
|
+
workbook = WriteExcel.new(@filename)
|
1718
|
+
worksheet = workbook.add_worksheet
|
1719
|
+
bold = workbook.add_format(:bold => 1)
|
1720
|
+
|
1721
|
+
# Add the data to the worksheet that the charts will refer to.
|
1722
|
+
headings = [ 'Category', 'Values 1', 'Values 2' ]
|
1723
|
+
data = [
|
1724
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
1725
|
+
[ 1, 4, 5, 2, 1, 5 ],
|
1726
|
+
[ 3, 6, 7, 5, 4, 3 ]
|
1727
|
+
]
|
1728
|
+
|
1729
|
+
worksheet.write('A1', headings, bold)
|
1730
|
+
worksheet.write('A2', data)
|
1731
|
+
|
1732
|
+
|
1733
|
+
###############################################################################
|
1734
|
+
#
|
1735
|
+
# Example 1. A minimal chart.
|
1736
|
+
#
|
1737
|
+
chart1 = workbook.add_chart(:type => Chart::Column)
|
1738
|
+
|
1739
|
+
# Add values only. Use the default categories.
|
1740
|
+
chart1.add_series( :values => '=Sheet1!$B$2:$B$7' )
|
1741
|
+
|
1742
|
+
###############################################################################
|
1743
|
+
#
|
1744
|
+
# Example 2. A minimal chart with user specified categories (X axis)
|
1745
|
+
# and a series name.
|
1746
|
+
#
|
1747
|
+
chart2 = workbook.add_chart(:type => Chart::Column)
|
1748
|
+
|
1749
|
+
# Configure the series.
|
1750
|
+
chart2.add_series(
|
1751
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1752
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1753
|
+
:name => 'Test data series 1'
|
1754
|
+
)
|
1755
|
+
|
1756
|
+
###############################################################################
|
1757
|
+
#
|
1758
|
+
# Example 3. Same as previous chart but with added title and axes labels.
|
1759
|
+
#
|
1760
|
+
chart3 = workbook.add_chart(:type => Chart::Column)
|
1761
|
+
|
1762
|
+
# Configure the series.
|
1763
|
+
chart3.add_series(
|
1764
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1765
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1766
|
+
:name => 'Test data series 1'
|
1767
|
+
)
|
1768
|
+
|
1769
|
+
# Add some labels.
|
1770
|
+
chart3.set_title( :name => 'Results of sample analysis' )
|
1771
|
+
chart3.set_x_axis( :name => 'Sample number' )
|
1772
|
+
chart3.set_y_axis( :name => 'Sample length (cm)' )
|
1773
|
+
|
1774
|
+
###############################################################################
|
1775
|
+
#
|
1776
|
+
# Example 4. Same as previous chart but with an added series
|
1777
|
+
#
|
1778
|
+
chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Column)
|
1779
|
+
|
1780
|
+
# Configure the series.
|
1781
|
+
chart4.add_series(
|
1782
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1783
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1784
|
+
:name => 'Test data series 1'
|
1785
|
+
)
|
1786
|
+
|
1787
|
+
# Add another series.
|
1788
|
+
chart4.add_series(
|
1789
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1790
|
+
:values => '=Sheet1!$C$2:$C$7',
|
1791
|
+
:name => 'Test data series 2'
|
1792
|
+
)
|
1793
|
+
|
1794
|
+
# Add some labels.
|
1795
|
+
chart4.set_title( :name => 'Results of sample analysis' )
|
1796
|
+
chart4.set_x_axis( :name => 'Sample number' )
|
1797
|
+
chart4.set_y_axis( :name => 'Sample length (cm)' )
|
1798
|
+
|
1799
|
+
###############################################################################
|
1800
|
+
#
|
1801
|
+
# Example 5. Same as Example 3 but as an embedded chart.
|
1802
|
+
#
|
1803
|
+
chart5 = workbook.add_chart(:type => Chart::Column, :embedded => 1)
|
1804
|
+
|
1805
|
+
# Configure the series.
|
1806
|
+
chart5.add_series(
|
1807
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1808
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1809
|
+
:name => 'Test data series 1'
|
1810
|
+
)
|
1811
|
+
|
1812
|
+
# Add some labels.
|
1813
|
+
chart5.set_title(:name => 'Results of sample analysis' )
|
1814
|
+
chart5.set_x_axis(:name => 'Sample number')
|
1815
|
+
chart5.set_y_axis(:name => 'Sample length (cm)')
|
1816
|
+
|
1817
|
+
# Insert the chart into the main worksheet.
|
1818
|
+
worksheet.insert_chart('E2', chart5)
|
1819
|
+
|
1820
|
+
# File save
|
1821
|
+
workbook.close
|
1822
|
+
|
1823
|
+
# do assertion
|
1824
|
+
compare_file("#{PERL_OUTDIR}/chart_column.xls", @filename)
|
1825
|
+
end
|
1826
|
+
|
1827
|
+
def test_chart_line
|
1828
|
+
workbook = WriteExcel.new(@filename)
|
1829
|
+
worksheet = workbook.add_worksheet
|
1830
|
+
bold = workbook.add_format(:bold => 1)
|
1831
|
+
|
1832
|
+
# Add the data to the worksheet that the charts will refer to.
|
1833
|
+
headings = [ 'Category', 'Values 1', 'Values 2' ]
|
1834
|
+
data = [
|
1835
|
+
[ 2, 3, 4, 5, 6, 7 ],
|
1836
|
+
[ 1, 4, 5, 2, 1, 5 ],
|
1837
|
+
[ 3, 6, 7, 5, 4, 3 ]
|
1838
|
+
]
|
1839
|
+
|
1840
|
+
worksheet.write('A1', headings, bold)
|
1841
|
+
worksheet.write('A2', data)
|
1842
|
+
|
1843
|
+
|
1844
|
+
###############################################################################
|
1845
|
+
#
|
1846
|
+
# Example 1. A minimal chart.
|
1847
|
+
#
|
1848
|
+
chart1 = workbook.add_chart(:type => Chart::Line)
|
1849
|
+
|
1850
|
+
# Add values only. Use the default categories.
|
1851
|
+
chart1.add_series( :values => '=Sheet1!$B$2:$B$7' )
|
1852
|
+
|
1853
|
+
###############################################################################
|
1854
|
+
#
|
1855
|
+
# Example 2. A minimal chart with user specified categories (X axis)
|
1856
|
+
# and a series name.
|
1857
|
+
#
|
1858
|
+
chart2 = workbook.add_chart(:type => Chart::Line)
|
1859
|
+
|
1860
|
+
# Configure the series.
|
1861
|
+
chart2.add_series(
|
1862
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1863
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1864
|
+
:name => 'Test data series 1'
|
1865
|
+
)
|
1866
|
+
|
1867
|
+
###############################################################################
|
1868
|
+
#
|
1869
|
+
# Example 3. Same as previous chart but with added title and axes labels.
|
1870
|
+
#
|
1871
|
+
chart3 = workbook.add_chart(:type => Chart::Line)
|
1872
|
+
|
1873
|
+
# Configure the series.
|
1874
|
+
chart3.add_series(
|
1875
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1876
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1877
|
+
:name => 'Test data series 1'
|
1878
|
+
)
|
1879
|
+
|
1880
|
+
# Add some labels.
|
1881
|
+
chart3.set_title( :name => 'Results of sample analysis' )
|
1882
|
+
chart3.set_x_axis( :name => 'Sample number' )
|
1883
|
+
chart3.set_y_axis( :name => 'Sample length (cm)' )
|
1884
|
+
|
1885
|
+
###############################################################################
|
1886
|
+
#
|
1887
|
+
# Example 4. Same as previous chart but with an added series
|
1888
|
+
#
|
1889
|
+
chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Line)
|
1890
|
+
|
1891
|
+
# Configure the series.
|
1892
|
+
chart4.add_series(
|
1893
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1894
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1895
|
+
:name => 'Test data series 1'
|
1896
|
+
)
|
1897
|
+
|
1898
|
+
# Add another series.
|
1899
|
+
chart4.add_series(
|
1900
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1901
|
+
:values => '=Sheet1!$C$2:$C$7',
|
1902
|
+
:name => 'Test data series 2'
|
1903
|
+
)
|
1904
|
+
|
1905
|
+
# Add some labels.
|
1906
|
+
chart4.set_title( :name => 'Results of sample analysis' )
|
1907
|
+
chart4.set_x_axis( :name => 'Sample number' )
|
1908
|
+
chart4.set_y_axis( :name => 'Sample length (cm)' )
|
1909
|
+
|
1910
|
+
###############################################################################
|
1911
|
+
#
|
1912
|
+
# Example 5. Same as Example 3 but as an embedded chart.
|
1913
|
+
#
|
1914
|
+
chart5 = workbook.add_chart(:type => Chart::Line, :embedded => 1)
|
1915
|
+
|
1916
|
+
# Configure the series.
|
1917
|
+
chart5.add_series(
|
1918
|
+
:categories => '=Sheet1!$A$2:$A$7',
|
1919
|
+
:values => '=Sheet1!$B$2:$B$7',
|
1920
|
+
:name => 'Test data series 1'
|
1921
|
+
)
|
1922
|
+
|
1923
|
+
# Add some labels.
|
1924
|
+
chart5.set_title(:name => 'Results of sample analysis' )
|
1925
|
+
chart5.set_x_axis(:name => 'Sample number')
|
1926
|
+
chart5.set_y_axis(:name => 'Sample length (cm)')
|
1927
|
+
|
1928
|
+
# Insert the chart into the main worksheet.
|
1929
|
+
worksheet.insert_chart('E2', chart5)
|
1930
|
+
|
1931
|
+
# File save
|
1932
|
+
workbook.close
|
1933
|
+
|
1934
|
+
# do assertion
|
1935
|
+
compare_file("#{PERL_OUTDIR}/chart_line.xls", @filename)
|
1936
|
+
end
|
1937
|
+
|
1938
|
+
def compare_file(expected, target)
|
1939
|
+
assert_equal(
|
1940
|
+
open(expected, 'rb') { |f| f.read },
|
1941
|
+
open(target, 'rb') { |f| f.read }
|
1942
|
+
)
|
1943
|
+
end
|
1944
|
+
end
|