rars / ng2csv Goto Github PK
View Code? Open in Web Editor NEWAngular service for saving data to CSV file.
License: MIT License
Angular service for saving data to CSV file.
License: MIT License
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 functionThe 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
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)
I would expect that null values will be like an empty string in a cell, displays nothing.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.