Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @molteni/export-csv with all npm packages installed. Try it out:

var exportCsv = require("@molteni/export-csv")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@molteni/export-csv v0.0.5

Quick and simply export JSON and tables data to CSV

export-csv

Blog - article

http://javaee.ch/2017/03/05/angular-and-javascript-export-your-data-to-csv-using-typescript/ Image of export

Example

Goal - Export your web table to Excel in a click

Many js applications show tables and data. Very often the business users need the possibility to export their data in excel. Most of the time a simple export (no server required) is enough.

Description

This package easily export to the CSV the content of an array of objects (JavaScript or JSON, e.g. table of data on the screen) to a format compatible with Excel.

The generated document is in UTF-8 with BOF. This allows the characters to be correctly showed in Excel.

Features

  • The library has been written in Typescript and target Angular (1.x, >=2).
  • It is possible to decide which columns export and in which order.

Installation

npm i @molteni/export-csv --save

or add to your package.json in the 'dependencies' : "_@molteni/export-csv": "^0.0.3_",

Usage

In Angular import the library with: import {ExportToCSV} from "@molteni/export-csv";

Use the library:

Export only one specific columns

exportColumnsToCSV(JSONListItemsToPublish : any[], fileName : string, columns : string[]);

exporter = new ExportToCSV();
exporter.exportColumnsToCSV(this.blogArticles, "filename", ["title"])
exporter = new ExportToCSV();
objectToExport = [{column : 'äàü£™ , ®, ©,'}, {column: 'second row'}];
exporter.exportColumnsToCSV(objectToExport, "filename", ["column"])

Export all the columns

exportAllToCSV(JSONListItemsToPublish : any[], fileName : string);

var exporter = new ExportToCSV();
exporter.exportColumnsToCSV(this.blogArticles, "filename")

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free