Class: SpreadsheetToArray::FromExcel

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadsheet_to_array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(byte_array) ⇒ FromExcel

Returns a new instance of FromExcel.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/spreadsheet_to_array.rb', line 16

def initialize(byte_array)

  require 'rjb'
  
  # JVM loading
  filedir = File.dirname(__FILE__) + '/.'
  # Memory settings
  memory = ['-Xms256M', '-Xmx512M']
  Rjb::load("#{filedir}/apache-poi/poi-3.7-20101029.jar", memory)
  
  # Import des packages Java
  begin
    @file_class               = Rjb::import('java.io.FileInputStream')
    @workbook_class           = Rjb::import('org.apache.poi.hssf.usermodel.HSSFWorkbook')
    @cell_class               = Rjb::import('org.apache.poi.hssf.usermodel.HSSFCell')
    @date_util_class          = Rjb::import('org.apache.poi.ss.usermodel.DateUtil')
    @byte_array_input_stream  = Rjb::import('java.io.ByteArrayInputStream')
  rescue
    raise "Impossible to load Java packages. Maybe the path of Apache POI is not correct."
  end      
  
  begin
    java_byte_array         = @byte_array_input_stream.new_with_sig('[B', byte_array)
    @book                   = @workbook_class.new(java_byte_array)
  rescue Exception => e
    raise "The document is not a valid Excel file: #{e}"
  end
  
  # Reglage du nom de la première feuille
  @sheet                    = @book.getSheetAt(0)
  
  # Valeurs récupérées depuis le tableur
  @values                   = []
  parse_sheet    
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



14
15
16
# File 'lib/spreadsheet_to_array.rb', line 14

def values
  @values
end