Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get data from csv using vue js

//<script type="text/javascript" src="https://oss.sheetjs.com/sheetjs/xlsx.full.min.js"></script>
//excel/csv

<template>
	<input type="file" @change="onFileChange" />
</template>

export default {
  methods: {
    onFileChange(event) {
      this.file = event.target.files ? event.target.files[0] : null;
      if (this.file) {
        const reader = new FileReader();

        reader.onload = (e) => {
          /* Parse data */
          const bstr = e.target.result;
          const wb = XLSX.read(bstr, { type: 'binary' , cellDates: true, dateNF: 'yyyy/mm/dd;@'});
          /* Get first worksheet */
          const wsname = wb.SheetNames[0];
          const ws = wb.Sheets[wsname];
          /* Convert array of arrays */
          const data = XLSX.utils.sheet_to_json(ws, { header: 1 });
          console.log(data)
        }

        reader.readAsBinaryString(this.file);
      }
    },
  }
};
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #data #csv #vue #js
ADD COMMENT
Topic
Name
1+4 =