class ExcelConnection
Public Class Methods
see new
optional block possible, where ExcelConnection#quit
gets
called on blocks end e.g. ExcelConnection::connect{|con| con.workbook
... }
# File lib/jruby_excelcom/excel_connection.rb, line 12 def self.connect(use_active_instance = false) con = self.new(use_active_instance) if block_given? yield(con) con.quit else con end end
initializes com manually, not recommended! happens automatically when an instance is created
# File lib/jruby_excelcom/excel_connection.rb, line 23 def self.initialize_com JavaExcelcom::ExcelConnection::initialize_com end
initializes com and connects to an excel instance
use_active_instance
-
whether an existing excel instance should be used or a new isntance should be created. Default value is
false
# File lib/jruby_excelcom/excel_connection.rb, line 5 def initialize(use_active_instance = false) @con = JavaExcelcom::ExcelConnection::connect(use_active_instance) end
uninitializes com manually, not recommended! should happen automatically
when ExcelConnection#quit
is called.
# File lib/jruby_excelcom/excel_connection.rb, line 28 def self.uninitialize_com JavaExcelcom::ExcelConnection::uninitialize_com end
Public Instance Methods
gets the active workbook
# File lib/jruby_excelcom/excel_connection.rb, line 56 def active_workbook Workbook.new(@con.getActiveWorkbook) end
whether dialog boxes should show up or not (e.g. when saving and overwriting a file)
# File lib/jruby_excelcom/excel_connection.rb, line 39 def display_alerts=(da) @con.setDisplayAlerts(da) end
quits the excel instance and uninitializes com
# File lib/jruby_excelcom/excel_connection.rb, line 51 def quit @con.quit end
gets excel version
# File lib/jruby_excelcom/excel_connection.rb, line 45 def version @con.getVersion end
whether the excel instance should be visible or not
# File lib/jruby_excelcom/excel_connection.rb, line 33 def visible=(v) @con.setVisible v end
opens a workbook. Optional block possible where workbook gets closed on
blocks end, e.g. con.workbook{|wb| puts wb.name }
file
-
workbook to be opened. Can be a string or a file object
# File lib/jruby_excelcom/excel_connection.rb, line 64 def workbook(file) if file.is_a? String wb = Workbook.new(@con.openWorkbook(java.io.File.new(file))) else wb = Workbook.new(@con.openWorkbook(java.io.File.new(file.path))) end if block_given? yield(wb) wb.close else wb end end