dropzone解析excel文件

import XLSX from 'xlsx'

dropzoneOptions: {
            url: 'dummy',
            thumbnailWidth: 50,
            maxFilesize: 50, //MB
            autoProcessQueue: false,
            headers: { "My-Awesome-Header": "header value" },
            accept: function(file, done) {
                // console.log("file:" + JSON.stringify(file));                
                var rABS = true
                var reader = new FileReader();
                reader.addEventListener("loadend", function(event) {
                    // console.log("event.target.result:" + event.target.result);
                    var data = event.target.result;
                    if(!rABS) data = new Uint8Array(data);
                    var workbook = XLSX.read(data, {type: rABS ? 'binary' : 'array', cellDates:true,
                        dateNF:'yyyy-mm-dd'});
                    // console.log("workbook:" + JSON.stringify(workbook));
                    let worksheet = workbook.Sheets[workbook.SheetNames[0]]
                    var rows = XLSX.utils.sheet_to_row_object_array(worksheet);
                    let oneFileChartDataArr = []
                    for(let i = 0; i < rows.length; i++) {
                        let oneRow = rows[i];
                        let keyArr = Object.keys(oneRow);
                        let date =  oneRow[keyArr[0]];
                        let nav =  oneRow[keyArr[1]];
                        console.log("###date:" + date + " nav:" + nav)
                        oneFileChartDataArr.push({
                            "x": date,
                            "y": nav
                        })
                    }
                    console.log("oneFileChartDataArr:" + JSON.stringify(oneFileChartDataArr));
                });
                if(rABS) reader.readAsBinaryString(file); else reader.readAsArrayBuffer(file);
                // reader.readAsText(file);
                // reader.readAsBinaryString(file);
            }
        }

你可能感兴趣的:(dropzone解析excel文件)