Method: Excelx#initialize

Defined in:
lib/roo/excelx.rb

#initialize(filename, packed = nil, file_warning = :error) ⇒ Excelx

initialization and opening of a spreadsheet file values for packed: :zip



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/roo/excelx.rb', line 88

def initialize(filename, packed=nil, file_warning = :error) #, create = false)
  super()
  @file_warning = file_warning
  file_type_check(filename,'.xlsx','an Excel-xlsx',packed)
  @tmpdir = GenericSpreadsheet.next_tmpdir
  @tmpdir = File.join(ENV['ROO_TMP'], @tmpdir) if ENV['ROO_TMP'] 
  unless File.exists?(@tmpdir)
    FileUtils::mkdir(@tmpdir)
  end
  filename = open_from_uri(filename) if filename[0,7] == "http://"
  filename = unzip(filename) if packed and packed == :zip
  @cells_read = Hash.new
  @filename = filename
  unless File.file?(@filename)
    FileUtils::rm_r(@tmpdir)
    raise IOError, "file #{@filename} does not exist"
  end
  @@nr += 1
  @file_nr = @@nr
  @comments_files = Array.new
  extract_content(@filename)
  file = File.new(File.join(@tmpdir, @file_nr.to_s+"_roo_workbook.xml"))
  @workbook_doc = Nokogiri::XML(file)
  file.close
  @shared_table = []
  if File.exist?(File.join(@tmpdir, @file_nr.to_s+'_roo_sharedStrings.xml'))
    file = File.new(File.join(@tmpdir, @file_nr.to_s+'_roo_sharedStrings.xml'))
    @sharedstring_doc = Nokogiri::XML(file)
    file.close
    read_shared_strings(@sharedstring_doc)
  end
  @styles_table = []
  @style_definitions = Array.new # TODO: ??? { |h,k| h[k] = {} }
  if File.exist?(File.join(@tmpdir, @file_nr.to_s+'_roo_styles.xml'))
    file = File.new(File.join(@tmpdir, @file_nr.to_s+'_roo_styles.xml'))
    @styles_doc = Nokogiri::XML(file)
    file.close
    read_styles(@styles_doc)
  end
  @sheet_doc = []
  @sheet_files.each_with_index do |item, i|
    file = File.new(item)
    @sheet_doc[i] = Nokogiri::XML(file)
    file.close
  end
  @comments_doc = []
  @comments_files.each_with_index do |item, i|
    file = File.new(item)
    @comments_doc[i] = Nokogiri::XML(file)
    file.close
  end
  FileUtils::rm_r(@tmpdir)
  @default_sheet = self.sheets.first
  @cell = Hash.new
  @cell_type = Hash.new
  @formula = Hash.new
  @first_row = Hash.new
  @last_row = Hash.new
  @first_column = Hash.new
  @last_column = Hash.new
  @header_line = 1
  @excelx_type = Hash.new
  @excelx_value = Hash.new
  @s_attribute = Hash.new # TODO: ggf. wieder entfernen nur lokal benoetigt
  @label = Hash.new
  @labels_read = false
  @comment = Hash.new
  @comments_read = Hash.new
end