我是靠谱客的博主 无奈煎饼,最近开发中收集的这篇文章主要介绍angular上传CSV转存到MySQL,如何上传CSV文件并使用angular2读取它们?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

i have a requirement of uploading a .CSV file and read them inside my component, i have gone through this blog but it has a .CSV file stored in a particular loaction, i want to upload the .CSV file and read them inside my component. How can i do it

Do we have any build in plugin which we can use? if not then how can we achieve this goal.

this is code which i have tried

view

(change)="changeListener($event)"

accept=".csv"/>

component

changeListener($event:Response): void {

debugger;

// i am not able to get the data in the CSV file

}

in the changeListener(), i am not able tom get the content of the .CSV file, can anyone help me on this?

thank you

解决方案

Upload your csv file to a location and get the csv file data. Please try this:-

Component.html:-

Component.ts:-

public changeListener(files: FileList){

console.log(files);

if(files && files.length > 0) {

let file : File = files.item(0);

console.log(file.name);

console.log(file.size);

console.log(file.type);

let reader: FileReader = new FileReader();

reader.readAsText(file);

reader.onload = (e) => {

let csv: string = reader.result as string;

console.log(csv);

}

}

}

最后

以上就是无奈煎饼为你收集整理的angular上传CSV转存到MySQL,如何上传CSV文件并使用angular2读取它们?的全部内容,希望文章能够帮你解决angular上传CSV转存到MySQL,如何上传CSV文件并使用angular2读取它们?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部