Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reference the surpass gem in examples. Tidy up and run all examples. …

…Derive excel file name from ruby file name.
  • Loading branch information...
commit 977208f7f28bb1fb81a1642ba4a513bd8f8ff89e 1 parent e1d830f
@ananelson ananelson authored
View
25 examples/big-16mb.rb
@@ -1,16 +1,14 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-w = Workbook.new
-s = w.add_sheet('0')
-
-# colcount = 200 + 1
-# rowcount = 6000 + 1
+book = Workbook.new
+s = book.add_sheet('0')
colcount = 200 + 1
rowcount = 6000 + 1
-t0 = Time.now
-puts "starting at #{t0.to_s}"
+start = Time.now
+puts "starting at #{start.to_s}"
colcount.times do |c|
rowcount.times do |r|
@@ -18,11 +16,10 @@
end
end
+t = Time.now - start
+puts "time elapsed (writing data to workbook) #{t.to_s}"
-t1 = Time.now - t0
-puts "elapsed #{t1.to_s}"
-
-w.save("big-16Mb.xls")
+book.save(__FILE__.gsub(/rb$/, "xls"))
-t2 = Time.now - t0
-puts "elapsed #{t2.to_s}"
+t = Time.now - start
+puts "time elapsed (writing workbook to file) #{t.to_s}"
View
42 examples/big-random-strings.rb
@@ -1,21 +1,16 @@
-require "lib/surpass"
-
-def String.random_alphanumeric(size=16)
- s = ""
- size.times { s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
- s
-end
+require "rubygems"
+require "surpass"
strings = File.read("spec/data/random-strings.txt").split("\n")
-w = Workbook.new
-s = w.add_sheet('0')
+book = Workbook.new
+s = book.add_sheet('0')
-colcount = 30 + 1
-rowcount = 30 + 1
+colcount = 100 + 1
+rowcount = 100 + 1
-t0 = Time.now
-puts "starting at #{t0.to_s}"
+start = Time.now
+puts "starting at #{start.to_s}"
colcount.times do |c|
rowcount.times do |r|
@@ -24,21 +19,10 @@ def String.random_alphanumeric(size=16)
end
end
+t = Time.now - start
+puts "time elapsed (writing data to workbook) #{t.to_s}"
-t1 = Time.now - t0
-puts "elapsed #{t1.to_s}"
-
-w.save("ruby-big-random-strings.xls")
-
-File.open("ruby-ws", "w") do |f|
- f.write s.to_biff
-end
-
-
-File.open("ruby-sst", "w") do |f|
- f.write w.sst.to_biff
-end
-
-t2 = Time.now - t0
-puts "elapsed #{t2.to_s}"
+book.save(__FILE__.gsub(/rb$/, "xls"))
+t = Time.now - start
+puts "time elapsed (writing workbook to file) #{t.to_s}"
View
9 examples/blanks.rb
@@ -1,4 +1,5 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
font0 = Font.new
font0.name = 'Times New Roman'
@@ -9,8 +10,8 @@
style0.font = font0
-wb = Workbook.new
-ws0 = wb.add_sheet('0')
+book = Workbook.new
+ws0 = book.add_sheet('0')
ws0.write(1, 1, 'Test', style0)
@@ -30,4 +31,4 @@
ws0.write_merge(5, 8, 6, 10, "")
-wb.save('examples/blanks.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
11 examples/col_width.rb
@@ -1,7 +1,8 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-w = Workbook.new
-ws = w.add_sheet('Hey, Dude')
+book = Workbook.new
+ws = book.add_sheet('Hey, Dude')
(6...80).each do |i|
fnt = Font.new
@@ -9,7 +10,7 @@
style = StyleFormat.new
style.font = fnt
ws.write(1, i, 'Test')
- ws.col(i).width = 256 * i
+ ws.set_column_width(i, i)
end
-w.save('col_width.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
9 examples/dates.rb
@@ -1,7 +1,8 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-w = Workbook.new
-ws = w.add_sheet('Hey, Dude')
+book = Workbook.new
+ws = book.add_sheet('Hey, Dude')
formats = [
'M/D/YY',
@@ -27,4 +28,4 @@
ws.write(i, 4, Time.now, style)
end
-w.save('dates.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
25 examples/format.rb
@@ -1,34 +1,23 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-font0 = Font.new
-font0.name = 'Times New Roman'
-font0.struck_out = true
-font0.bold = true
+style0 = StyleFormat.new(:font_name => 'Times New Roman', :font_struck_out => true, :font_bold => true)
-style0 = StyleFormat.new
-style0.font = font0
-
-
-wb = Workbook.new
-ws0 = wb.add_sheet('0')
+book = Workbook.new
+ws0 = book.add_sheet('0')
ws0.write(1, 1, 'Test', style0)
(0...0x53).each do |i|
- fnt = Font.new
- fnt.name = 'Arial'
- fnt.colour_index = i
- fnt.outline = true
+ style = StyleFormat.new(:font_name => 'Arial', :font_color_index => i, :font_outline => true)
borders = Borders.new
borders.left = i
- style = StyleFormat.new
- style.font = fnt
style.borders = borders
ws0.write(i, 2, 'colour', style)
ws0.write(i, 3, hex(i), style0)
end
-wb.save('format.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
10 examples/hash_argument_to_styleformat.rb
@@ -1,10 +0,0 @@
-require "lib/surpass"
-
-fmt = StyleFormat.new({:font_colour => 'purple', :font_italic => true, :font_bold => true, :font_name => "Times New Roman"})
-
-w = Workbook.new("named-colours-test.xls")
-s = w.add_sheet
-
-s.write(0, 0, "hey!", fmt)
-
-w.save
View
9 examples/image.rb
@@ -1,9 +1,10 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-w = Workbook.new
-ws = w.add_sheet('Image')
+book = Workbook.new
+ws = book.add_sheet('Image')
ws.insert_bitmap('examples/python.bmp', 2, 2)
ws.insert_bitmap('examples/python.bmp', 10, 2)
-w.save('image.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
13 examples/merged.rb
@@ -1,4 +1,5 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
fnt = Font.new
fnt.name = 'Arial'
@@ -21,10 +22,10 @@
style.alignment = al
-wb = Workbook.new
-ws0 = wb.add_sheet('sheet0')
-ws1 = wb.add_sheet('sheet1')
-ws2 = wb.add_sheet('sheet2')
+book = Workbook.new
+ws0 = book.add_sheet
+ws1 = book.add_sheet
+ws2 = book.add_sheet
(0...0x200).step(2) do |i|
ws0.write_merge(i, i+1, 1, 5, "test #{i}", style)
@@ -32,4 +33,4 @@
ws2.write_merge(i, i+1, 1, 7 + (i%10), "test #{i}", style)
end
-wb.save('merged.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
11 examples/merged0.rb
@@ -1,7 +1,8 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-wb = Workbook.new
-ws0 = wb.add_sheet('sheet0')
+book = Workbook.new
+ws0 = book.add_sheet
fnt = Font.new
@@ -21,6 +22,6 @@
ws0.write_merge(3, 3, 1, 5, 'test1', style)
ws0.write_merge(4, 10, 1, 5, 'test2', style)
-ws0.col(1).width = 0x0d00
+ws0.set_column_width(1, 0x0d00)
-wb.save('merged0.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
11 examples/merged1.rb
@@ -1,7 +1,8 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-wb = Workbook.new
-ws0 = wb.add_sheet('sheet0')
+book = Workbook.new
+ws0 = book.add_sheet
fnt1 = Font.new
fnt1.name = 'Verdana'
@@ -92,7 +93,7 @@
ws0.merge(3, 3, 1, 5, style1)
ws0.merge(4, 10, 1, 6, style2)
ws0.merge(14, 16, 1, 7, style3)
-ws0.col(1).width = 0x0d00
+ws0.set_column_width(1, 0x0d00)
-wb.save('merged1.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
11 examples/num_formats.rb
@@ -1,10 +1,11 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-w = Workbook.new
-ws = w.add_sheet('Hey, Dude')
+book = Workbook.new
+ws = book.add_sheet
fmts = [
- 'general',
+ 'General',
'0',
'0.00',
'#,##0',
@@ -51,4 +52,4 @@
ws.write(i, 4, -1278.9078, style)
end
-w.save('num_formats.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
9 examples/numbers.rb
@@ -1,7 +1,8 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-w = Workbook.new
-ws = w.add_sheet('Hey, Dude')
+book = Workbook.new
+ws = book.add_sheet
ws.write(0, 0, 1)
ws.write(1, 0, 1.23)
@@ -18,4 +19,4 @@
ws.write(2, 2, -12345678.90780980)
ws.write(3, 2, -123456.78)
-w.save('numbers.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
85 examples/outline.rb
@@ -1,4 +1,5 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
fnt = Font.new
fnt.name = 'Arial'
@@ -15,9 +16,9 @@
style.font = fnt
style.borders = borders
-wb = Workbook.new
+book = Workbook.new
-ws0 = wb.add_sheet('Rows Outline')
+ws0 = book.add_sheet('Rows Outline')
ws0.write_merge(1, 1, 1, 5, 'test 1', style)
ws0.write_merge(2, 2, 1, 4, 'test 1', style)
@@ -29,18 +30,18 @@
ws0.write_merge(8, 8, 1, 4, 'test 1', style)
ws0.write_merge(9, 9, 1, 3, 'test 5', style)
-ws0.row(1).level = 1
-ws0.row(2).level = 1
-ws0.row(3).level = 2
-ws0.row(4).level = 2
-ws0.row(5).level = 2
-ws0.row(6).level = 2
-ws0.row(7).level = 2
-ws0.row(8).level = 1
-ws0.row(9).level = 1
+ws0.fetch_or_create_row(1).level = 1
+ws0.fetch_or_create_row(2).level = 1
+ws0.fetch_or_create_row(3).level = 2
+ws0.fetch_or_create_row(4).level = 2
+ws0.fetch_or_create_row(5).level = 2
+ws0.fetch_or_create_row(6).level = 2
+ws0.fetch_or_create_row(7).level = 2
+ws0.fetch_or_create_row(8).level = 1
+ws0.fetch_or_create_row(9).level = 1
-ws1 = wb.add_sheet('Columns Outline')
+ws1 = book.add_sheet('Columns Outline')
ws1.write_merge(1, 1, 1, 5, 'test 1', style)
ws1.write_merge(2, 2, 1, 4, 'test 1', style)
@@ -52,18 +53,18 @@
ws1.write_merge(8, 8, 1, 4, 'test 1', style)
ws1.write_merge(9, 9, 1, 3, 'test 5', style)
-ws1.col(1).level = 1
-ws1.col(2).level = 1
-ws1.col(3).level = 2
-ws1.col(4).level = 2
-ws1.col(5).level = 2
-ws1.col(6).level = 2
-ws1.col(7).level = 2
-ws1.col(8).level = 1
-ws1.col(9).level = 1
+ws1.fetch_or_create_column(1).level = 1
+ws1.fetch_or_create_column(2).level = 1
+ws1.fetch_or_create_column(3).level = 2
+ws1.fetch_or_create_column(4).level = 2
+ws1.fetch_or_create_column(5).level = 2
+ws1.fetch_or_create_column(6).level = 2
+ws1.fetch_or_create_column(7).level = 2
+ws1.fetch_or_create_column(8).level = 1
+ws1.fetch_or_create_column(9).level = 1
-ws2 = wb.add_sheet('Rows and Columns Outline')
+ws2 = book.add_sheet('Rows and Columns Outline')
ws2.write_merge(1, 1, 1, 5, 'test 1', style)
ws2.write_merge(2, 2, 1, 4, 'test 1', style)
@@ -75,15 +76,15 @@
ws2.write_merge(8, 8, 1, 4, 'test 1', style)
ws2.write_merge(9, 9, 1, 3, 'test 5', style)
-ws2.row(1).level = 1
-ws2.row(2).level = 1
-ws2.row(3).level = 2
-ws2.row(4).level = 2
-ws2.row(5).level = 2
-ws2.row(6).level = 2
-ws2.row(7).level = 2
-ws2.row(8).level = 1
-ws2.row(9).level = 1
+ws2.fetch_or_create_row(1).level = 1
+ws2.fetch_or_create_row(2).level = 1
+ws2.fetch_or_create_row(3).level = 2
+ws2.fetch_or_create_row(4).level = 2
+ws2.fetch_or_create_row(5).level = 2
+ws2.fetch_or_create_row(6).level = 2
+ws2.fetch_or_create_row(7).level = 2
+ws2.fetch_or_create_row(8).level = 1
+ws2.fetch_or_create_row(9).level = 1
ws2.write_merge(1, 1, 1, 5, 'test 1', style)
ws2.write_merge(2, 2, 1, 4, 'test 1', style)
@@ -95,15 +96,15 @@
ws2.write_merge(8, 8, 1, 4, 'test 1', style)
ws2.write_merge(9, 9, 1, 3, 'test 5', style)
-ws2.col(1).level = 1
-ws2.col(2).level = 1
-ws2.col(3).level = 2
-ws2.col(4).level = 2
-ws2.col(5).level = 2
-ws2.col(6).level = 2
-ws2.col(7).level = 2
-ws2.col(8).level = 1
-ws2.col(9).level = 1
+ws2.fetch_or_create_column(1).level = 1
+ws2.fetch_or_create_column(2).level = 1
+ws2.fetch_or_create_column(3).level = 2
+ws2.fetch_or_create_column(4).level = 2
+ws2.fetch_or_create_column(5).level = 2
+ws2.fetch_or_create_column(6).level = 2
+ws2.fetch_or_create_column(7).level = 2
+ws2.fetch_or_create_column(8).level = 1
+ws2.fetch_or_create_column(9).level = 1
-wb.save('outline.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
19 examples/panes.rb
@@ -1,14 +1,15 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
# TODO this is broken in both Ruby and Python
-w = Workbook.new
-ws1 = w.add_sheet('sheet 1')
-ws2 = w.add_sheet('sheet 2')
-ws3 = w.add_sheet('sheet 3')
-ws4 = w.add_sheet('sheet 4')
-ws5 = w.add_sheet('sheet 5')
-ws6 = w.add_sheet('sheet 6')
+book = Workbook.new
+ws1 = book.add_sheet
+ws2 = book.add_sheet
+ws3 = book.add_sheet
+ws4 = book.add_sheet
+ws5 = book.add_sheet
+ws6 = book.add_sheet
0.upto(0x100) do |i|
ws1.write(i/0x10, i%0x10, i)
@@ -43,5 +44,5 @@
ws6.vert_split_pos = 40
ws4.vert_split_first_visible = 2
-w.save('panes.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
20 examples/protection.rb
@@ -1,4 +1,5 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
fnt = Font.new
fnt.name = 'Arial'
@@ -15,9 +16,9 @@
style.font = fnt
style.borders = borders
-wb = Workbook.new
+book = Workbook.new
-ws0 = wb.add_sheet('Rows Outline')
+ws0 = book.add_sheet('Rows Outline')
ws0.write_merge(1, 1, 1, 5, 'test 1', style)
ws0.write_merge(2, 2, 1, 4, 'test 1', style)
@@ -40,7 +41,7 @@
ws0.row(9).level = 1
-ws1 = wb.add_sheet('Columns Outline')
+ws1 = book.add_sheet('Columns Outline')
ws1.write_merge(1, 1, 1, 5, 'test 1', style)
ws1.write_merge(2, 2, 1, 4, 'test 1', style)
@@ -63,7 +64,7 @@
ws1.col(9).level = 1
-ws2 = wb.add_sheet('Rows and Columns Outline')
+ws2 = book.add_sheet('Rows and Columns Outline')
ws2.write_merge(1, 1, 1, 5, 'test 1', style)
ws2.write_merge(2, 2, 1, 4, 'test 1', style)
@@ -124,7 +125,8 @@
ws2.scen_protect = true
ws2.password = "ok"
-wb.protect = true
-wb.wnd_protect = true
-wb.obj_protect = true
-wb.save('protection.xls')
+book.protect = true
+book.wnd_protect = true
+book.obj_protect = true
+
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
9 examples/row_styles.rb
@@ -1,7 +1,8 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-w = Workbook.new
-ws = w.add_sheet('Hey, Dude')
+book = Workbook.new
+ws = book.add_sheet
(6..80).each do |i|
fnt = Font.new
@@ -12,4 +13,4 @@
ws.row(i).style = style
end
-w.save('row_styles.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
9 examples/row_styles_empty.rb
@@ -1,7 +1,8 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-w = Workbook.new
-ws = w.add_sheet('Hey, Dude')
+book = Workbook.new
+ws = book.add_sheet
(6..80).each do |i|
fnt = Font.new
@@ -11,4 +12,4 @@
ws.row(i).style = style
end
-w.save('row_styles_empty.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
9 examples/set_cell_and_range_style.rb
@@ -1,11 +1,12 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
-w = Workbook.new("set_cell_style.xls")
-s = w.add_sheet
+book = Workbook.new
+s = book.add_sheet
s.write_arrays([%w{a b c d e}, %w{F G H I J}, %w{k l m n o}])
s.set_cell_style(2, 2, StyleFormat.new(:font_color => "yellow"))
s.set_range_style(0..1, 1..2, StyleFormat.new(:font_color => "purple"))
-w.save
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
9 examples/write_arrays.rb
@@ -1,4 +1,5 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
font0 = Font.new
font0.name = 'Times New Roman'
@@ -7,9 +8,9 @@
style0.font = font0
-wb = Workbook.new
-s = wb.add_sheet
+book = Workbook.new
+s = book.add_sheet
s.write_array_to_column(methods.sort, 0, 0, style0)
-wb.save('examples/arrays.xls')
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
10 examples/ws_props.rb
@@ -1,4 +1,5 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
props = \
[
@@ -18,7 +19,6 @@
'show_outline',
'remove_splits',
'selected',
- 'hidden',
'page_preview',
'first_visible_row',
'first_visible_col',
@@ -72,9 +72,9 @@
'copies_num',
]
-wb = Workbook.new
-ws = wb.add_sheet('sheet')
+book = Workbook.new
+sheet = book.add_sheet('sheet')
props.each do |p|
- puts "#{p} #{ws.send(p.to_sym)}"
+ puts "#{p} #{sheet.send(p.to_sym)}"
end
Please sign in to comment.
Something went wrong with that request. Please try again.