Home > OS >  reading Excel file on Javascript
reading Excel file on Javascript

Time:06-27

I want to read only one row each time on excel. I can read all datas in excel but I couldn't limit it. Either I can read only 1 column in all rows or the all data. How can I read just 1 row on javascript?

I use this script and this src:

<script src="https://unpkg.com/[email protected]/bundle/read-excel-file.min.js"></script>
<body>
   <input type="file" id="input">
   <script>
        var input = document.getElementById('input');
        input.addEventListener("change", function (){
            readXlsxFile(input.files[0]).then(function (data){
                data.map((row,index)=>{
                    var location= document.createTextNode(row);
                    console.log(location)

CodePudding user response:

This code section went poorly. So

<script>
    var input = document.getElementById('input');
    input.addEventListener("change", function (){
        readXlsxFile(input.files[0]).then(function (data){
            data.map((row,index)=>{
                var location= document.createTextNode(row);
                console.log(location)

CodePudding user response:

If you need one row, don't map over entire file:

   readXlsxFile(input.files[0]).then(data => {
      console.log(data[0]) // supposed to print the first row
   })
  • Related