Permalink
Browse files

Rename ExcelFormula to Formula, and ExcelFormulaGrammar to ExcelFormula.

  • Loading branch information...
1 parent 5e39a4f commit daa8f4a8d44689c03b1bb3497cda6334e135fa23 Ana Nelson committed May 3, 2010
View
@@ -1,4 +1,4 @@
-== 1.0.0 / 2009-10-27
+== 0.0.9 / 2010-05-03
* 1 major enhancement
- * Birthday!
+ * Some formula support enabled, see examples/formulas.rb to see what is supported.
View
@@ -24,5 +24,5 @@ task 'gem:release' => 'test:run'
desc "run antlr compiler"
task :antlr do
- `cd lib/surpass; antlr4ruby ExcelFormulaGrammar.g`
+ `cd lib/surpass; antlr4ruby ExcelFormula.g`
end
Binary file not shown.
@@ -0,0 +1,14 @@
+require "lib/surpass"
+
+class Parent
+ def index
+ 0
+ end
+end
+
+cell = FormulaCell.new(Parent.new, 0, 0, ExcelFormula.new("1"))
+
+File.open("formula-cell.bin", "w") do |f|
+ f.write cell.to_biff
+end
+
Binary file not shown.
@@ -0,0 +1,15 @@
+require "lib/surpass"
+
+class Parent
+ def index
+ 0
+ end
+end
+
+rpn = ExcelFormula.new("1").to_biff
+record = FormulaRecord.new(0, 0, 0, rpn)
+
+File.open("formula-record.bin", "w") do |f|
+ f.write record.to_biff
+end
+
View
@@ -0,0 +1,10 @@
+require "rubygems"
+require "surpass"
+
+book = Workbook.new
+ws = book.add_sheet
+
+formula = ExcelFormula.new("1+1")
+ws.write(0, 0, formula)
+
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
@@ -0,0 +1,44 @@
+require "rubygems"
+require "surpass"
+
+book = Workbook.new
+ws = book.add_sheet
+
+ws.write(0, 0, Formula.new("-(1+1)"))
+ws.write(1, 0, Formula.new("-(1+1)/(-2-2)"))
+ws.write(2, 0, Formula.new("-(134.8780789+1)"))
+ws.write(3, 0, Formula.new("-(134.8780789e-10+1)"))
+ws.write(4, 0, Formula.new("-1/(1+1)+9344"))
+
+ws.write(0, 1, Formula.new("-(1+1)"))
+ws.write(1, 1, Formula.new("-(1+1)/(-2-2)"))
+ws.write(2, 1, Formula.new("-(134.8780789+1)"))
+ws.write(3, 1, Formula.new("-(134.8780789e-10+1)"))
+ws.write(4, 1, Formula.new("-1/(1+1)+9344"))
+
+ws.write(0, 2, Formula.new("A1*B1"))
+ws.write(1, 2, Formula.new("A2*B2"))
+ws.write(2, 2, Formula.new("A3*B3"))
+#ws.write(3, 2, Formula.new("A4*B4*sin(pi()/4)"))
+#ws.write(4, 2, Formula.new("A5%*B5*pi()/1000"))
+
+##############
+## NOTE: parameters are separated by semicolon!!!
+##############
+
+
+ws.write(5, 2, Formula.new("C1+C2+C3+C4+C5/(C1+C2+C3+C4/(C1+C2+C3+C4/(C1+C2+C3+C4)+C5)+C5)-20.3e-2"))
+ws.write(5, 3, Formula.new("C1^2"))
+#ws.write(6, 2, Formula.new("SUM(C1;C2;;;;;C3;;;C4)"))
+#ws.write(6, 3, Formula.new("SUM($A$1:$C$5)"))
+
+ws.write(7, 0, Formula.new('"lkjljllkllkl"'))
+ws.write(7, 1, Formula.new('"yuyiyiyiyi"'))
+#ws.write(7, 2, Formula.new('A8 & B8 & A8'))
+#ws.write(8, 2, Formula.new('now()'))
+
+ws.write(10, 2, Formula.new('TRUE'))
+ws.write(11, 2, Formula.new('FALSE'))
+#ws.write(12, 3, Formula.new('IF(A1>A2;3;"hkjhjkhk")'))
+
+book.save(__FILE__.gsub(/rb$/, "xls"))
View
@@ -1,7 +1,7 @@
module Surpass
# :stopdoc:
- VERSION = '0.0.8'
+ VERSION = '0.0.9'
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
# :startdoc:
@@ -40,13 +40,22 @@ def self.require_all_libs_relative_to( fname, dir = "." )
Dir.glob(search_me).sort.each do |rb|
next if File.basename(rb) === File.basename(__FILE__) # skip surpass.rb
+ next if File.basename(rb) =~ /^ExcelFormula/ unless FORMULAS_AVAILABLE
require rb
end
end
end # module Surpass
-require "rubygems"
-require "antlr3"
+begin
+ require 'rubygems'
+ require 'antlr3'
+ FORMULAS_AVAILABLE = true
+rescue Exception => e
+ puts "antlr3 gem not found, formulas not available. Install antlr3 to enable formulas."
+ FORMULAS_AVAILABLE = false
+end
+
Surpass.require_all_libs_relative_to(__FILE__)
require 'date'
+
@@ -1,4 +1,4 @@
-grammar ExcelFormulaGrammar;
+grammar ExcelFormula;
options {
language = Ruby;
@@ -125,16 +125,16 @@ primary[arg_type]
}
| ref2d_tok = REF2D
{
- r, c = Utils.cell_to_packed_rowcol(ref2d_tok.text)
+ r, c = Utilities.cell_to_packed_rowcol(ref2d_tok.text)
ptg = PTGREFR + RVA_DELTA[arg_type]
@rpn += [ptg, r, c].pack("Cv2")
}
| ref2d1_tok = REF2D COLON ref2d2_tok = REF2D
{
- r1, c1 = Utils.cell_to_packed_rowcol(ref2d1_tok.text)
- r2, c2 = Utils.cell_to_packed_rowcol(ref2d2_tok.text)
+ r1, c1 = Utilities.cell_to_packed_rowcol(ref2d1_tok.text)
+ r2, c2 = Utilities.cell_to_packed_rowcol(ref2d2_tok.text)
ptg = PTGAREAR + RVA_DELTA[arg_type]
- self.rpn += struct.pack("Cv4", ptg, r1, r2, c1, c2)
+ @rpn += [ptg, r1, r2, c1, c2].pack("Cv4")
}
| sheet1 = sheet
@@ -145,13 +145,13 @@ primary[arg_type]
{
ptg = PTGREF3DR + RVA_DELTA[arg_type]
rpn_ref2d = ""
- r1, c1 = Utils.cell_to_packed_rowcol(ref3d_ref2d.text)
+ r1, c1 = Utilities.cell_to_packed_rowcol(ref3d_ref2d.text)
rpn_ref2d = [0x0000, r1, c1].pack("v3")
}
( COLON ref3d_ref2d2= REF2D
{
ptg = PTGAREA3DR + RVA_DELTA[arg_type]
- r2, c2 = Utils.cell_to_packed_rowcol(ref3d_ref2d2.text)
+ r2, c2 = Utilities.cell_to_packed_rowcol(ref3d_ref2d2.text)
rpn_ref2d = [0x0000, r1, r2, c1, c2].pack("v5")
}
)?
Oops, something went wrong.

0 comments on commit daa8f4a

Please sign in to comment.