How to upload a CSV file and read them using angular2?

前端 未结 4 1027
野趣味
野趣味 2020-12-15 05:49

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

4条回答
  •  悲哀的现实
    2020-12-15 06:36

    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);
           }
        }
    }
    

提交回复
热议问题