### Execute bundle command Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Run this command in your terminal to install the gem after adding it to your Gemfile. ```bash $ bundle ``` -------------------------------- ### Install gem manually Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Install the gem directly using the gem command. ```bash $ gem install simple_xlsx_reader ``` -------------------------------- ### Install simple_xlsx_reader via Gemfile Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Add the gem to your application's Gemfile to manage dependencies. ```ruby gem 'simple_xlsx_reader' ``` -------------------------------- ### Process XLSX rows idiomatically Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Example of using the library to map row data into a hash using standard Ruby enumerables. ```ruby # quick example having fun w/ ruby doc = SimpleXlsxReader.open(file_path) # or SimpleXlsxReader.parse(string_or_io) doc.sheets.first.rows.each(headers: {id: /ID/}) .with_index.with_object({}) do |(row, index), acc| acc[row[:id]] = index end ``` -------------------------------- ### Open and stream XLSX data Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Demonstrates opening a workbook and streaming rows using various header configurations. ```ruby doc = SimpleXlsxReader.open('/path/to/workbook.xlsx') doc.sheets # => [<#SXR::Sheet>, ...] doc.sheets.first.name # 'Sheet1' rows = doc.sheets.first.rows # rows.each # an ready to chain or stream rows.each {} # Streams the rows to your block rows.each(headers: true) {} # Streams row-hashes rows.each(headers: {id: /ID/}) {} # finds & maps headers, streams rows.slurp # Slurps rows into memory as a 2D array ``` -------------------------------- ### Open an XLSX sheet Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Obtain a rows proxy from the first sheet of an XLSX file. ```ruby rows = SimpleXlsxReader.open('suited_heroes.xlsx').sheets.first.rows ``` -------------------------------- ### Git workflow commands Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Standard commands for creating a feature branch, committing changes, and pushing to a remote repository. ```bash git checkout -b my-new-feature ``` ```bash git commit -am 'Add some feature' ``` ```bash git push origin my-new-feature ``` -------------------------------- ### Stream rows with custom header mapping Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Use a hash to map header keys and identify the correct header row. ```ruby rows.each(headers: {id: /ID/, name: /Name/}).with_object({}) do |row, acc| acc[row[:id]] = row[:name] end ``` -------------------------------- ### Stream rows with block-based header detection Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Use a block to identify the header row when mapping is complex. ```ruby object_map = { Hero => { id: 'Hero ID', name: 'Hero Name', location: 'Location' } } HEADERS = ['Hero ID', 'Hero Name', 'Location'] rows.each(headers: ->(row) { (HEADERS & row).any? }) do |row| object_map.each_pair do |klass, attribute_map| attributes = attribute_map.each_pair.with_object({}) do |(key, header), attrs| attrs[key] = row[header] end klass.new(attributes) end end ``` -------------------------------- ### Stream rows with headers Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Process rows using headers to map values into an object. ```ruby rows.each(headers: true).with_object({}) do |row, acc| acc[row['Hero ID']] = row['Hero Name'] end ``` -------------------------------- ### Stream rows Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md Iterate over rows using the each method. ```ruby rows.each { |row| ... } ``` -------------------------------- ### Cell load error structure Source: https://github.com/woahdae/simple_xlsx_reader/blob/master/README.md The format of the error hash when catch_cell_load_errors is enabled. ```ruby { [rownum, colnum] => '[error]' } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.