概述
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读取它们?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复