JS reads the data from the EXCEL table, modifies the format and outputs it.

clipboard.png
excel
clipboard.png

clipboard.png
excel

clipboard.png
this is my code

< html >

<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="http://oss.sheetjs.com/js-xlsx/xlsx.full.min.js"></script>
    <script src="http://oss.sheetjs.com/js-xlsx/FileSaver.min.js"></script>
</head>

<body>
    <input type="file"onchange="importf(this)" />
    <div id="demo"></div>
    <script>
        
var to_json2 = function to_json(workbook) {
    var result = {};
    workbook.SheetNames.forEach(function(sheetName) {// workbook.SheetNames 
        var roa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName],{header:1});//json
        if(roa.length) result[sheetName] = roa;
    });
    console.log(JSON.stringify(result, 2, 2));
    return JSON.stringify(result, 2, 2);
};



function do_file(files) {
    rABS = true;
    var f = files[0];
    var reader = new FileReader();
    reader.onload = function(e) {
        if(typeof console !== "undefined") console.log("onload", new Date(), rABS);
        var data = e.target.result;
        if(!rABS) data = new Uint8Array(data);
        var wb=XLSX.read(data, {type: rABS ? "binary" : "array"});

        var json=to_json2(wb);
        
    };
    if(rABS) reader.readAsBinaryString(f);// html5
    else reader.readAsArrayBuffer(f);//ArrayBuffer html5
};
        
function importf(obj) {//
   if(!obj.files) {return;}
   do_file(obj.files);         
}

problem description

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

Jul.22,2021

in fact, you can store the data of the excle table in the database through node.js, and then read the data from the database, which makes it clearer

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3da6a-2c3c3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3da6a-2c3c3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?