lib/formulae/compile/formula_builder.rb in rubyfromexcel-0.0.4 vs lib/formulae/compile/formula_builder.rb in rubyfromexcel-0.0.5

- old
+ new

@@ -66,11 +66,13 @@ def brackets(*expression) "(#{expression.map{ |e| e.visit(self)}.join})" end - def named_reference(name, worksheet = formula_cell.worksheet) + def named_reference(name, worksheet = nil) + worksheet ||= formula_cell ? formula_cell.worksheet : nil + return ":name" unless worksheet worksheet.named_references[name.to_method_name] || worksheet.workbook.named_references[name.to_method_name] || ":name" end @@ -88,13 +90,23 @@ def row_range(start_area,end_area) "r(#{cell(start_area)},#{cell(end_area)})" end + def external_reference(external_reference_number,remainder_of_reference) + puts "Warning, external references not supported (#{formula_cell}) #{remainder_of_reference}" + remainder_of_reference.visit(self) + end + def sheet_reference(sheet_name,reference) sheet_name = $1 if sheet_name.to_s =~ /^(\d+)\.0+$/ + if sheet_name =~ /^\[\d+\]/ + puts "Warning, #{formula_cell} refers to an external workbook in '#{sheet_name}'" + sheet_name.gsub!(/^\[\d+\]/,'') + end if reference.type == :named_reference + return ":name" unless formula_cell worksheet = formula_cell.worksheet.workbook.worksheets[SheetNames.instance[sheet_name]] raise Exception.new("#{sheet_name.inspect} not found in #{SheetNames.instance} and therefore in #{formula_cell.worksheet.workbook.worksheets.keys}") unless worksheet named_reference(reference.first,worksheet) else "#{SheetNames.instance[sheet_name]}.#{reference.visit(self)}" @@ -155,9 +167,10 @@ excel_function :sum excel_function :sumif excel_function :sumifs excel_function :subtotal excel_function :sumproduct + excel_function :round def standard_function(name_to_use_in_ruby,args) "#{name_to_use_in_ruby}(#{args.map {|a| a.visit(self) }.join(',')})" end \ No newline at end of file