Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xlsx_importer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xlsx_importer

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

XlsxImporter

I really like Smarter CSV but as MS Excel cannot export CSV files in unicode, I need to import the spreadsheet directly to preserve the unicode characters.

XlsxImporter is a port from Smarter CSV with a few specific options for spreadsheets import. It uses SimpleXlsxReader to read the MS Excel xlsx file. It only support xlsx files.

Installation

Add this line to your application's Gemfile:

gem 'xlsx_importer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install xlsx_importer

Usage

    > XlsxImporter.process('/tmp/people.xlsx', options = {})
     => [ {:first_name=>"Dan", :last_name=>"McAllister"},
          {:first_name=>"Lucy", :last_name=>"Laweless"} ]

Options

A few options from Smarter CVS are supported, a few more were added.

OptionDefaultExplanation
:key_mapping_hashnila hash which maps headers from the spreadsheet to keys in the result hash
:remove_unmapped_keysfalsewhen using :key_mapping option, should non-mapped keys / columns be removed?
:sheet0the number of the sheet inside the workbook to parse
:strip_whitespacetrueremove whitespace before/after values and headers
:downcase_headertruedowncase all column headers
:strip_chars_from_headersnilRegExp to remove extraneous characters from the header line
:remove_empty_hashestrueremove / ignore any hashes which don't have any key/value pairs
:remove_empty_valuestrueremove values which have nil or empty strings as values
:remove_zero_valuesfalseremove values which have a numeric value equal to zero / 0
:remove_values_matchingnilremoves key/value pairs if value matches given regular expressions
:header_row1row number with the headers
:date_keysnilArray with the keys of date fields to perform DB compatible validation

Example

  result = XlsxImporter.process('tmp/test.xlsx', {
      :key_mapping_hash => {
          :name => :full_name,
          :date_of_creation => :created_at,
          :date_of_termination => :deleted_at,
      },
      :date_keys => [:created_at, :deleted_at],
      :remove_unmapped_keys => true,
      :strip_chars_from_headers => /[\/\(\)]/,
      :remove_values_matching => /^[\.\-]$/,
      :sheet => 1,
      :header_row => 3
  })

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 23 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc