Class: BxBuilderChain::Processors::Xlsx

Inherits:
Base
  • Object
show all
Defined in:
lib/bx_builder_chain/processors/xlsx.rb

Constant Summary collapse

EXTENSIONS =
[".xlsx", ".xlsm"].freeze
CONTENT_TYPES =
["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"].freeze

Instance Method Summary collapse

Methods included from DependencyHelper

#depends_on

Constructor Details

#initializeXlsx

Returns a new instance of Xlsx.



9
10
11
12
# File 'lib/bx_builder_chain/processors/xlsx.rb', line 9

def initialize(*)
  depends_on "roo"
  require "roo"
end

Instance Method Details

#parse(data) ⇒ Array<Array<String>>

Parse the document and return the text

Parameters:

  • data (File)

Returns:

  • (Array<Array<String>>)

    Array of rows, each row is an array of cells



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bx_builder_chain/processors/xlsx.rb', line 17

def parse(data)
  output = []
  
  xlsx_file = Roo::Spreadsheet.open(data)
  xlsx_file.each_with_pagename do |sheet, rows|
    output << rows.map do |row|
      row.map { |i| i.to_s.strip }
    end
  end

  output
end