Socket
Socket
Sign inDemoInstall

ember-spreadsheet-export

Package Overview
Dependencies
647
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ember-spreadsheet-export

Provides ability to export a set of json data as excel or csv file.


Version published
Weekly downloads
139
increased by1.46%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

ember-spreadsheet-export

Addon that encapsulates ability to render a data set as either excel or csv.

Forked from roofstock/ember-cli-data-export.

Differences from ember-cli-data-export include:
  • Dependencies have been updated to address various deprecations
  • The undocumented export-selector and export-selector-onselect components have been removed, in order to remove the dependency on ember-select-list, which hasn't been updated in a long time
  • The csv and excel services are not automatically injected
  • The dummy app now has content (a couple of buttons to generate demo files)
  • Multiple sheets can be added to a single XLSX file
  • [v0.3.0] The excel service supports merging cells via an additional merges option
  • [v0.4.0] The csv service supports a new raw option, which disables quoting and escaping of cell contents
  • [v0.5.0] The csv service supports a new autoQuote option, which only quotes/escapes cells which need it (those containing quotes, commas or newlines).

Installation

  • ember install ember-spreadsheet-export

Usage

  • uses js-xlsx library for rendering excel content.
  • automatically injects a service for both excel and csv format
  • feed a datastructure that's an array of arrays, where each internal array is the set of data to be rendered for that row.
  • Example: [['Title 1', 'Title 2', 'Title 3'],['row1cell1', 'row1cell2', 'row1cell3'],['row2cell1', 'row2cell2', 'row2cell3']]
Merging Cells (Excel only)

In order to merge cells, an array of merges can be passed in the options hash. Each element of this array should be an object taking the following form:

{
  s: {
    r: 0,
    c: 0,
  },
  e: {
    r: 1,
    c: 0,
  },
}

s defines the start of the range to be merged, and e the end of the range. Within each, r is the row index and c is the column index. The example above would therefore merge the first two cells in the first column.

Examples

   // Don't forget to inject the service(s) as needed
   csv: service(),
   excel: service(),
   
   // Then go ahead and use it in your code
   let data = [
       ['Title 1', 'Title 2', 'Title 3'],
       ['row1cell1', 'row1cell2', 'row1cell3'],
       ['row2cell1', 'row2cell2', 'row2cell3']
   ];

   if (type === 'MultiExcel') {
     let sheets = [
       {
         name: 'Demo sheet',
         data
       },
       {
         name: 'Supplemental sheet',
         data: [
           ['Foo', 'Bar'],
           ['Baz', 'Foobar']
         ]
       }
     ];
     this.excel.export(sheets, {multiSheet: true, fileName: 'test.xlsx'});
   } else if (type === 'Excel') {
     this.excel.export(data, {sheetName: 'sheet1', fileName: 'test.xlsx'});
   } else if (type === 'CSV') {
     this.csv.export(data, {fileName: 'test.csv', autoQuote: true});
   }

Keywords

FAQs

Last updated on 25 May 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc