npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-ztk-csvexporter

v1.0.3

Published

> Generate CSV files with single line of code!

Downloads

5

Readme

Export CSV in Angular

Generate CSV files with single line of code!

Prerequisites

The library created in Angular 6. To avoid any unwanted behaviour it's recommended to install it to Angular 6 projects.

Installation

npm install ngx-ztk-csvexporter --save

Usage example

import { Component, OnInit } from '@angular/core';

// 1. IMPORT PACKAGE
import { NgxZtkCSVExporter, NgxZtkCSVConfigProps } from 'ngx-ztk-csvexporter';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

// 2. ADD TO THE CONSTRUCTOR
  constructor(private exporter: NgxZtkCSVExporter) {}

  ngOnInit(): void {}

// 3. CALL DECLARED SERVICE IN A FUNCTION - OPTIONAL: SET CONFIGURATION SETTINGS IN EXTERNAL OBJECT
  exportFile() {
	// You can find more configuration options in the documentation below.
    let confg: NgxZtkCSVConfigProps = { fieldSeperator: ';', autoDownload:false };
    let csvText = this.exporter.GenerateCSV({ a: { b: 10, c: 11 }, b: ['one', 'two'] }, confg);
  }
}

Export Configurations

| Property | Default value | Description | | :--------------------- | :-----------: | --------------------------------------------------------------------------------------------------------------------------------------------------- | | filename | sheet1 | Recommended to set this property when filenameDialog is set to false | | showFilenameDialog | true | Open a prompt dialog window to set CSV filename. Set to false can cause unwanted behaviour. Default filename or manually set filename will be used. | | fieldSeperator | , | Field seperator character | | decimalPoint | . | Decimal number seperator character. Set to ,,locale'' it tells client's system to use it's default seperator. | | keepLeadingSpace | false | Kept leading spaces can cause unwanted changes. Field will set to be String in Excel to preserve leading or trailing spaces. | | keepLeadingZeros | false | Kept leading zeros can cause unwanted changes. Field will set to be String in Excel to preserve zeros. | | containsHeader | false | Set to true can cause unwanted behaviour. First row set to be the exported file header. | | customHeader | [] | Pass a custom string array of header names | | insertBom | true | Add a BOM charachter to the beginning of the CSV. Set to false can cause unwanted behaviour. Latin extended charachters may not be displayed. | | localeDateFormat | true | Objects with Date type set to localeDateString. Set to false can cause unwanted changes. Field will set to American English date string. | | boolToYesNo | false | Set to true can cause unwanted changes. Field will set Yes or No based on boolean value. | | autoDownload | true | Set to false can cause unwanted changes. The function returns a CSV formatted string. |

Allowed data formats

// Array with objects
let data1 = [
  {
    a_a: 10,
    a_b: 'one'
  },
  {
    b_a: 5,
    b_b: 'eleven'
  }
];
//Object with objects
let data2 = {
  a: {
    a_a: 10,
    a_b: 'one'
  },
  b: {
    b_a: 5,
    b_b: 'eleven'
  }
};
// Mixed
let data3 = [
  {
    a_a: 10,
    a_b: 'one'
  },
  [5, 'eleven']
];

// Single types allowed too
let data4 = 'one';

let data5 = [
  {
    a_a: 10,
    a_b: 'one'
  },
  'eleven',
  10,
  ['two', 7]
];

// ONLY TWO DIMENSION WILL BE HANDLED, DEEPER PLACED OBJECTS RETURN UNDEFINED VALUE