spreadsheet-excel 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/CHANGES +124 -0
  2. data/CVS/Entries +10 -0
  3. data/CVS/Repository +1 -0
  4. data/CVS/Root +1 -0
  5. data/README +69 -0
  6. data/doc/CVS/Entries +3 -0
  7. data/doc/CVS/Repository +1 -0
  8. data/doc/CVS/Root +1 -0
  9. data/doc/format.txt +330 -0
  10. data/doc/spreadsheet.txt +178 -0
  11. data/examples/CVS/Entries +3 -0
  12. data/examples/CVS/Repository +1 -0
  13. data/examples/CVS/Root +1 -0
  14. data/examples/example_basic.rb +27 -0
  15. data/examples/example_format.rb +69 -0
  16. data/lib/CVS/Entries +1 -0
  17. data/lib/CVS/Repository +1 -0
  18. data/lib/CVS/Root +1 -0
  19. data/lib/spreadsheet/CVS/Entries +7 -0
  20. data/lib/spreadsheet/CVS/Repository +1 -0
  21. data/lib/spreadsheet/CVS/Root +1 -0
  22. data/lib/spreadsheet/biffwriter.rb +46 -0
  23. data/lib/spreadsheet/excel.rb +13 -0
  24. data/lib/spreadsheet/format.rb +359 -0
  25. data/lib/spreadsheet/olewriter.rb +178 -0
  26. data/lib/spreadsheet/workbook.rb +279 -0
  27. data/lib/spreadsheet/worksheet.rb +449 -0
  28. data/test/CVS/Entries +9 -0
  29. data/test/CVS/Repository +1 -0
  30. data/test/CVS/Root +1 -0
  31. data/test/perl_output/CVS/Entries +10 -0
  32. data/test/perl_output/CVS/Repository +1 -0
  33. data/test/perl_output/CVS/Root +1 -0
  34. data/test/perl_output/README +31 -0
  35. data/test/perl_output/f_font_biff +0 -0
  36. data/test/perl_output/f_font_key +1 -0
  37. data/test/perl_output/f_xf_biff +0 -0
  38. data/test/perl_output/ole_write_header +0 -0
  39. data/test/perl_output/ws_colinfo +1 -0
  40. data/test/perl_output/ws_store_dimensions +1 -0
  41. data/test/perl_output/ws_store_selection +1 -0
  42. data/test/perl_output/ws_store_window2 +1 -0
  43. data/test/tc_all.rb +6 -0
  44. data/test/tc_biff.rb +62 -0
  45. data/test/tc_excel.rb +26 -0
  46. data/test/tc_format.rb +133 -0
  47. data/test/tc_ole.rb +125 -0
  48. data/test/tc_workbook.rb +71 -0
  49. data/test/tc_worksheet.rb +142 -0
  50. data/test/ts_all.rb +9 -0
  51. metadata +103 -0
@@ -0,0 +1 @@
1
+ RubySpreadsheet/test
data/test/CVS/Root ADDED
@@ -0,0 +1 @@
1
+ :ext:hwyss@rubyspreadsheet.cvs.sourceforge.net:/cvsroot/rubyspreadsheet
@@ -0,0 +1,10 @@
1
+ /README/1.5/Mon Oct 10 22:50:37 2005/-kb/
2
+ /f_font_biff/1.1/Wed Dec 4 00:15:06 2002/-kb/
3
+ /f_font_key/1.1/Wed Dec 4 00:14:48 2002/-kb/
4
+ /f_xf_biff/1.1/Wed Dec 4 00:14:31 2002/-kb/
5
+ /ole_write_header/1.1/Mon Oct 10 22:51:03 2005/-kb/
6
+ /ws_colinfo/1.1/Thu Nov 28 04:52:55 2002/-kb/
7
+ /ws_store_dimensions/1.1/Thu Nov 28 04:53:19 2002/-kb/
8
+ /ws_store_selection/1.1/Thu Nov 28 04:53:19 2002/-kb/
9
+ /ws_store_window2/1.1/Thu Nov 28 04:53:19 2002/-kb/
10
+ D
@@ -0,0 +1 @@
1
+ RubySpreadsheet/test/perl_output
@@ -0,0 +1 @@
1
+ :ext:hwyss@rubyspreadsheet.cvs.sourceforge.net:/cvsroot/rubyspreadsheet
@@ -0,0 +1,31 @@
1
+ ###############################################################################
2
+ # This file contains sample output from the Spreadsheet::WriteExcel Perl
3
+ # module. Used for testing file sizes/contents
4
+ ###############################################################################
5
+
6
+ Files:
7
+
8
+ ws_ -> from Worksheet.pm
9
+ f_ -> from Format.pm
10
+ ole_ -> from OLEWriter.pm
11
+
12
+ f_font_biff
13
+ Output of the _get_font call
14
+
15
+ f_font_key
16
+ Output of the _get_font_key call
17
+
18
+ f_xf_biff
19
+ Output of the _get_xf call
20
+
21
+ ws_colinfo
22
+ Output of the _store_colinfo call (default values)
23
+
24
+ ws_store_dimensions
25
+ Output of the _store_dimensions call
26
+
27
+ ws_store_window2
28
+ Output of the _store_window call
29
+
30
+ ws_store_selection
31
+ Output of the _store_selection call
Binary file
@@ -0,0 +1 @@
1
+ Arial100004000000327670
Binary file
Binary file
@@ -0,0 +1 @@
1
+ 15
@@ -0,0 +1 @@
1
+ 14
@@ -0,0 +1 @@
1
+ 19
@@ -0,0 +1 @@
1
+ 14
data/test/tc_all.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "tc_biff"
2
+ require "tc_ole"
3
+ require "tc_workbook"
4
+ require "tc_worksheet"
5
+ require "tc_format"
6
+ require "tc_excel"
data/test/tc_biff.rb ADDED
@@ -0,0 +1,62 @@
1
+ #######################################################
2
+ # tc_biff.rb
3
+ #
4
+ # Test suite for the BIFFWriter class (biffwriter.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 "biffwriter"
15
+
16
+ class TC_BIFFWriter < Test::Unit::TestCase
17
+ def setup
18
+ @biff = BIFFWriter.new
19
+ end
20
+
21
+ def test_append_no_error
22
+ assert_nothing_raised{ @biff.append("World") }
23
+ end
24
+
25
+ def test_prepend_no_error
26
+ assert_nothing_raised{ @biff.prepend("Hello") }
27
+ end
28
+
29
+ def test_data_added
30
+ assert_nothing_raised{ @biff.append("Hello", "World") }
31
+ assert_equal("HelloWorld", @biff.data, "Bad data contents")
32
+ assert_equal(10, @biff.datasize, "Bad data size")
33
+ end
34
+
35
+ def test_data_prepended
36
+ assert_nothing_raised{ @biff.append("Hello") }
37
+ assert_nothing_raised{ @biff.prepend("World") }
38
+ assert_equal("WorldHello", @biff.data, "Bad data contents")
39
+ end
40
+
41
+ def test_store_bof_length
42
+ assert_nothing_raised{ @biff.store_bof }
43
+ assert_equal(12, @biff.datasize, "Bad data size after store_bof call")
44
+ end
45
+
46
+ def test_store_eof_length
47
+ assert_nothing_raised{ @biff.store_eof }
48
+ assert_equal(4, @biff.datasize, "Bad data size after store_eof call")
49
+ end
50
+
51
+ def test_datasize_mixed
52
+ assert_nothing_raised{ @biff.append("Hello") }
53
+ assert_nothing_raised{ @biff.prepend("World") }
54
+ assert_nothing_raised{ @biff.store_bof }
55
+ assert_nothing_raised{ @biff.store_eof }
56
+ assert_equal(26, @biff.datasize, "Bad data size for mixed data")
57
+ end
58
+
59
+ def teardown
60
+ @biff = nil
61
+ end
62
+ end
data/test/tc_excel.rb ADDED
@@ -0,0 +1,26 @@
1
+ #########################################
2
+ # tc_excel.rb
3
+ #
4
+ # Tests for the Excel class (excel.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 "biffwriter"
15
+ require "olewriter"
16
+ require "format"
17
+ require "workbook"
18
+ require "worksheet"
19
+ require "excel"
20
+ require "ftools"
21
+
22
+ class TC_Excel < Test::Unit::TestCase
23
+ def test_version
24
+ assert_equal("0.3.4", Spreadsheet::Excel::VERSION)
25
+ end
26
+ end
data/test/tc_format.rb ADDED
@@ -0,0 +1,133 @@
1
+ #####################################################
2
+ # tc_format.rb
3
+ #
4
+ # Test suite for the Format class (format.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 "biffwriter"
15
+ require "olewriter"
16
+ require "workbook"
17
+ require "worksheet"
18
+ require "format"
19
+
20
+ class TC_Format < Test::Unit::TestCase
21
+
22
+ def setup
23
+ @ruby_file = "xf_test"
24
+ @format = Format.new
25
+ end
26
+
27
+ def test_xf_biff_size
28
+ perl_file = "perl_output/f_xf_biff"
29
+ size = File.size(perl_file)
30
+ @fh = File.new(@ruby_file,"w+")
31
+ @fh.print(@format.xf_biff)
32
+ @fh.close
33
+ rsize = File.size(@ruby_file)
34
+ assert_equal(size,rsize,"File sizes not the same")
35
+ end
36
+
37
+ # Because of the modifications to bg_color and fg_color, I know this
38
+ # test will fail. This is ok.
39
+ #def test_xf_biff_contents
40
+ # perl_file = "perl_output/f_xf_biff"
41
+ # @fh = File.new(@ruby_file,"w+")
42
+ # @fh.print(@format.xf_biff)
43
+ # @fh.close
44
+ # contents = IO.readlines(perl_file)
45
+ # rcontents = IO.readlines(@ruby_file)
46
+ # assert_equal(contents,rcontents,"Contents not the same")
47
+ #end
48
+
49
+ def test_font_biff_size
50
+ perl_file = "perl_output/f_font_biff"
51
+ @fh = File.new(@ruby_file,"w+")
52
+ @fh.print(@format.font_biff)
53
+ @fh.close
54
+ contents = IO.readlines(perl_file)
55
+ rcontents = IO.readlines(@ruby_file)
56
+ assert_equal(contents,rcontents,"Contents not the same")
57
+ end
58
+
59
+ def test_font_biff_contents
60
+ perl_file = "perl_output/f_font_biff"
61
+ @fh = File.new(@ruby_file,"w+")
62
+ @fh.print(@format.font_biff)
63
+ @fh.close
64
+ contents = IO.readlines(perl_file)
65
+ rcontents = IO.readlines(@ruby_file)
66
+ assert_equal(contents,rcontents,"Contents not the same")
67
+ end
68
+
69
+ def test_get_font_key_size
70
+ perl_file = "perl_output/f_font_key"
71
+ @fh = File.new(@ruby_file,"w+")
72
+ @fh.print(@format.font_key)
73
+ @fh.close
74
+ assert_equal(File.size(perl_file),File.size(@ruby_file),"Bad file size")
75
+ end
76
+
77
+ def test_get_font_key_contents
78
+ perl_file = "perl_output/f_font_key"
79
+ @fh = File.new(@ruby_file,"w+")
80
+ @fh.print(@format.font_key)
81
+ @fh.close
82
+ contents = IO.readlines(perl_file)
83
+ rcontents = IO.readlines(@ruby_file)
84
+ assert_equal(contents,rcontents,"Contents not the same")
85
+ end
86
+
87
+ def test_color
88
+ assert_nothing_raised{ @format.color = "blue" }
89
+ assert_equal(0x0C,@format.color,"Bad color value")
90
+ end
91
+
92
+ def test_color_valid
93
+ colors = %w/aqua black blue brown cyan fuchsia gray grey green lime/
94
+ colors << %w/magenta navy orange purple red silver white yellow/
95
+ colors.flatten!
96
+
97
+ colors.each{ |color|
98
+ assert_nothing_raised{ @format.color = color }
99
+ }
100
+ end
101
+
102
+ def test_color_bogus
103
+ assert_raises(ArgumentError){ @format.color = "blah" }
104
+ end
105
+
106
+ def test_align
107
+ @format.align
108
+ assert_equal(0,@format.text_h_align,"Bad text_h_align")
109
+ assert_equal(2,@format.text_v_align,"Bad text_v_align")
110
+ end
111
+
112
+ def test_align_center
113
+ @format.align = "center"
114
+ assert_equal(2,@format.text_h_align,"Bad text_h_align")
115
+ assert_equal(2,@format.text_v_align,"Bad text_v_align")
116
+ end
117
+
118
+ def test_bold
119
+ @format.bold=1
120
+ assert_equal(true,@format.bold,"Bad bold value")
121
+ end
122
+
123
+ def teardown
124
+ begin
125
+ @pfh.close
126
+ rescue NameError
127
+ # no op
128
+ end
129
+ File.delete(@ruby_file) if File.exist?(@ruby_file)
130
+ @format = nil
131
+ end
132
+
133
+ end
data/test/tc_ole.rb ADDED
@@ -0,0 +1,125 @@
1
+ ###########################################################################
2
+ # t_ole.rb
3
+ #
4
+ # Test suite for the OLEWriter class (olewriter.rb)
5
+ #
6
+ # In some cases, even though the file sizes are identical, the files
7
+ # themselves do not appear to be identical. The Perl output appears to
8
+ # contain a newline which the Ruby output does not.
9
+ ###########################################################################
10
+ base = File.basename(Dir.pwd)
11
+ if base == "test" || base =~ /spreadsheet/i
12
+ Dir.chdir("..") if base == "test"
13
+ $LOAD_PATH.unshift(Dir.pwd + "/lib/spreadsheet")
14
+ Dir.chdir("test") rescue nil
15
+ end
16
+
17
+ require "test/unit"
18
+ require "olewriter"
19
+
20
+ class TC_OLE < Test::Unit::TestCase
21
+
22
+ def setup
23
+ @file = "test.ole"
24
+ @ole = OLEWriter.new(@file)
25
+ end
26
+
27
+ def test_constructor
28
+ assert_nothing_raised{ OLEWriter.new("foo.ole") }
29
+ assert_nothing_raised{ OLEWriter.new(File.open("foo.ole", "w+")) }
30
+ assert_kind_of(OLEWriter, @ole)
31
+ end
32
+
33
+ def test_constants
34
+ assert_equal(7087104, OLEWriter::MaxSize)
35
+ assert_equal(4096, OLEWriter::BlockSize)
36
+ assert_equal(512, OLEWriter::BlockDiv)
37
+ assert_equal(127, OLEWriter::ListBlocks)
38
+ end
39
+
40
+ def test_calculate_sizes
41
+ assert_respond_to(@ole, :calculate_sizes)
42
+ assert_nothing_raised{ @ole.calculate_sizes }
43
+ assert_equal(0, @ole.big_blocks)
44
+ assert_equal(1, @ole.list_blocks)
45
+ assert_equal(0, @ole.root_start)
46
+ end
47
+
48
+ def test_set_size_too_big
49
+ err = "Should have raised MaxSizeError"
50
+ assert_raises(MaxSizeError, err){ @ole.set_size(999999999) }
51
+ end
52
+
53
+ def test_book_size_large
54
+ assert_nothing_raised{ @ole.set_size(8192) }
55
+ assert_equal(8192, @ole.book_size)
56
+ end
57
+
58
+ def test_book_size_small
59
+ assert_nothing_raised{ @ole.set_size(2048) }
60
+ assert_equal(4096, @ole.book_size)
61
+ end
62
+
63
+ def test_biff_size
64
+ assert_nothing_raised{ @ole.set_size(2048) }
65
+ assert_equal(2048, @ole.biff_size)
66
+ end
67
+
68
+ def test_size_allowed
69
+ assert_nothing_raised{ @ole.set_size }
70
+ assert_equal(true, @ole.size_allowed)
71
+ end
72
+
73
+ def test_big_block_size_default
74
+ assert_nothing_raised{ @ole.set_size }
75
+ assert_nothing_raised{ @ole.calculate_sizes }
76
+ assert_equal(8, @ole.big_blocks, "Bad big block size")
77
+ end
78
+
79
+ def test_big_block_size_rounded_up
80
+ assert_nothing_raised{ @ole.set_size(4099) }
81
+ assert_nothing_raised{ @ole.calculate_sizes }
82
+ assert_equal(9, @ole.big_blocks, "Bad big block size")
83
+ end
84
+
85
+ def test_list_block_size
86
+ assert_nothing_raised{ @ole.set_size }
87
+ assert_nothing_raised{ @ole.calculate_sizes }
88
+ assert_equal(1, @ole.list_blocks, "Bad list block size")
89
+ end
90
+
91
+ def test_root_start_size_default
92
+ assert_nothing_raised{ @ole.set_size }
93
+ assert_nothing_raised{ @ole.calculate_sizes }
94
+ assert_equal(8, @ole.big_blocks, "Bad root start size")
95
+ end
96
+
97
+ def test_root_start_size_rounded_up
98
+ assert_nothing_raised{ @ole.set_size(4099) }
99
+ assert_nothing_raised{ @ole.calculate_sizes }
100
+ assert_equal(9, @ole.big_blocks, "Bad root start size")
101
+ end
102
+
103
+ def test_write_header
104
+ assert_nothing_raised{ @ole.write_header }
105
+ #assert_nothing_raised{ @ole.close }
106
+ #assert_equal(512, File.size(@file))
107
+ end
108
+
109
+ def test_write_big_block_depot
110
+ assert_nothing_raised{ @ole.write_big_block_depot }
111
+ #assert_nothing_raised{ @ole.close }
112
+ #assert_equal(8, File.size(@file))
113
+ end
114
+
115
+ def test_write_property_storage_size
116
+ assert_nothing_raised{ @ole.write_property_storage }
117
+ #assert_nothing_raised{ @ole.close }
118
+ #assert_equal(512, File.size(@file))
119
+ end
120
+
121
+ def teardown
122
+ @ole.close rescue nil
123
+ File.unlink(@file) if File.exists?(@file)
124
+ end
125
+ end
@@ -0,0 +1,71 @@
1
+ #####################################################
2
+ # t_workbook.rb
3
+ #
4
+ # Test suite for the Workbook class (workbook.rb)
5
+ # Requires testunit 0.1.8 or greater to run properly
6
+ #####################################################
7
+ base = File.basename(Dir.pwd)
8
+ if base == "test" || base =~ /spreadsheet/i
9
+ Dir.chdir("..") if base == "test"
10
+ $LOAD_PATH.unshift(Dir.pwd + "/lib/spreadsheet")
11
+ Dir.chdir("test") rescue nil
12
+ end
13
+
14
+ require "test/unit"
15
+ require "biffwriter"
16
+ require "olewriter"
17
+ require "workbook"
18
+ require "worksheet"
19
+ require "format"
20
+
21
+ class TC_Workbook < Test::Unit::TestCase
22
+
23
+ def setup
24
+ @wb = Workbook.new("test.xls")
25
+ end
26
+
27
+ def test_add_worksheet
28
+ assert_nothing_raised{ ws = @wb.add_worksheet }
29
+ end
30
+
31
+ def test_calc_sheet_offsets
32
+ ws = @wb.add_worksheet
33
+ assert_nothing_raised{ @wb.calc_sheet_offsets }
34
+ end
35
+
36
+ def test_store_window1
37
+ assert_nothing_raised{ @wb.store_window1 }
38
+ end
39
+
40
+ def test_store_all_fonts
41
+ assert_nothing_raised{ @wb.store_all_fonts }
42
+ end
43
+
44
+ def test_store_xf
45
+ assert_nothing_raised{ @wb.store_xf(0xFFF5) }
46
+ end
47
+
48
+ def test_store_all_xfs
49
+ assert_nothing_raised{ @wb.store_all_xfs }
50
+ end
51
+
52
+ def test_store_style
53
+ assert_nothing_raised{ @wb.store_style }
54
+ end
55
+
56
+ def test_store_boundsheet
57
+ assert_nothing_raised{ @wb.store_boundsheet("test",0) }
58
+ end
59
+
60
+ def test_add_format
61
+ assert_nothing_raised{ @wb.add_format }
62
+ assert_equal(2,@wb.formats.length,"Bad number of formats")
63
+ end
64
+
65
+ def teardown
66
+ @wb.close
67
+ @wb = nil
68
+ File.delete("test.xls") if File.exists?("test.xls")
69
+ end
70
+
71
+ end