Class: SimpleTextExtract::FormatExtractor::XlsX

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_text_extract/format_extractor/xls_x.rb

Instance Attribute Summary

Attributes inherited from Base

#file

Instance Method Summary collapse

Methods inherited from Base

#initialize, #missing_dependency?

Constructor Details

This class inherits a constructor from SimpleTextExtract::FormatExtractor::Base

Instance Method Details

#extractObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple_text_extract/format_extractor/xls_x.rb', line 6

def extract
  require "roo"

  spreadsheet = Roo::Spreadsheet.open(file, only_visible_sheets: true)

  text = []

  spreadsheet.each_with_pagename do |name, sheet|
    text << name
    1.upto(sheet.last_row.to_i) { |row| text << sheet.row(row) }
  end

  text.flatten.join(" ")
end