class ExcelConnection

Public Class Methods

connect(use_active_instance = false) { |con| ... } click to toggle source

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
initialize_com() click to toggle source

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
new(use_active_instance = false) click to toggle source

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
uninitialize_com() click to toggle source

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

active_workbook() click to toggle source

gets the active workbook

# File lib/jruby_excelcom/excel_connection.rb, line 56
def active_workbook
  Workbook.new(@con.getActiveWorkbook)
end
Also aliased as: getActiveWorkbook
display_alerts=(da) click to toggle source

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
Also aliased as: setDisplayAlerts
getActiveWorkbook()
Alias for: active_workbook
getVersion()
Alias for: version
openWorkbook(file)
Alias for: workbook
open_workbook(file)
Alias for: workbook
quit() click to toggle source

quits the excel instance and uninitializes com

# File lib/jruby_excelcom/excel_connection.rb, line 51
def quit
  @con.quit
end
setDisplayAlerts(da)
Alias for: display_alerts=
setVisible(v)
Alias for: visible=
version() click to toggle source

gets excel version

# File lib/jruby_excelcom/excel_connection.rb, line 45
def version
  @con.getVersion
end
Also aliased as: getVersion
visible=(v) click to toggle source

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
Also aliased as: setVisible
workbook(file) { |wb| ... } click to toggle source

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
Also aliased as: openWorkbook, open_workbook