Permalink
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...
ananelson committed Feb 5, 2009
1 parent e1d830f commit 977208f7f28bb1fb81a1642ba4a513bd8f8ff89e
View
@@ -1,28 +1,25 @@
-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|
s.write(r, c, "BIG")
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}"
@@ -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
@@ -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
@@ -1,15 +1,16 @@
-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
fnt.height = i*20
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
@@ -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
@@ -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"))
@@ -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
@@ -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
@@ -1,4 +1,5 @@
-require "lib/surpass"
+require "rubygems"
+require "surpass"
fnt = Font.new
fnt.name = 'Arial'
@@ -21,15 +22,15 @@
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)
ws1.write_merge(i, i, 1, 7, "test #{i}", style)
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
@@ -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
@@ -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
@@ -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
@@ -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"))
Oops, something went wrong.

0 comments on commit 977208f

Please sign in to comment.