Giter VIP home page Giter VIP logo

ng2csv's People

Contributors

dependabot[bot] avatar rars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

adnanmc vsiestov

ng2csv's Issues

saveAs is not a function

Hello:

I would like to use this library for a specific part of my project. When I tried to follow the example given in the documentation, I got this error:

TypeError: file_saver_1.saveAs is not a function
The code in the download function is this:

 public download(): void {
    try {
      this.ng2Csv.download([
        {
          id: 1,
          name: 'Alice'
        },
        {
          id: 2,
          name: 'Bob'
        }
      ],
        'names.csv');
    } catch (e) {
      alert(e);
    }
  }

As additional data. I got a similar error using the file-saver library in direct way, but I could find a solution using this code in my component:

declare var saveAs: any; 

Instead of this:

import { saveAs } from 'file-saver';

In this ocation, the code of the download function is this:

public download(): void {
        try {
          let file = new Blob(['hello world'], { type: 'text/csv;charset=utf-8' });
          saveAs(file, ''helloworld'.csv');
        } catch (e) {
          alert(e);
        }

And you be able to download the helloword.csv file generated.

Thanks for your help.

Regards

exception when trying to access a value of "null"

Error Case:

In a cell i have a value, which is null. This will break the download() with the following error:

Subscriber.js:242 Uncaught TypeError: Cannot read property 'indexOf' of null at Ng2CsvService.webpackJsonp.1016.Ng2CsvService.escapeRowValue (Ng2Csv.service.js:51) at Ng2Csv.service.js:42 at Array.map (<anonymous>) at Ng2CsvService.webpackJsonp.1016.Ng2CsvService.convertToCsv (Ng2Csv.service.js:42) at Ng2CsvService.webpackJsonp.1016.Ng2CsvService.download (Ng2Csv.service.js:18) at BatchComponent.webpackJsonp.1146.BatchComponent.startDownload (batch.component.ts:169) at BatchComponent.webpackJsonp.1146.BatchComponent.downloadSelected (batch.component.ts:138) at Object.eval [as handleEvent] (BatchComponent.html:113) at handleEvent (core.es5.js:11998) at callWithDebugContext (core.es5.js:13467)

Expected Behaviour:

I would expect that null values will be like an empty string in a cell, displays nothing.

Fields missing in some objects not accounted for

I have a JSON object in this way where some fields are not mandatory in the JSON as shown below.
[ { id: 1, name: 'Alice', City:Madison, Phno:9191234567 },
{ id: 2, name: 'Bob' ,City:New York },
{ id: 2, name: 'Bob',City:Miami,Phno:9191234567 },
{ id: 2, name: 'Bob' ,City:Atlanta,Phno:9191234567 } ]
It gave me a toString() undefined error. Since there was no Phno field in the 2nd object, the field value was being taken as undefined and undefined.toString() was giving me the error in runtime.
I added a line to the _loop_1 function in the AutoCsvRowMapper.js file definition by keeping an if else condition. That fixed everything.
Let me know if you would be open to incorporating this fix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.