Load Server Excel File into SpreadJS

Posted by: sam.benson on 29 December 2020, 12:34 pm EST

  • Posted 29 December 2020, 12:34 pm EST

    Hi

    Trying to load a server Excel file into the VueJS SpreadJS example as a proof of concept for data capture to then load into a database.

    imported Excel as '@grapecity\spread-excelio' after npm install (v 14.04)

    Hacking dataService.js and added


    getDataFromFile() {
    let xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://localhost:3000/src/assets/data.xlsx', true);
    xhr.setRequestHeader(
    "Content-type",
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8"
    );
    xhr.responseType = 'blob';
    xhr.send();
    xhr.onloadend = function () {
    if (xhr.status != 200) {
    alert(`Error loading file`);
    } else {
    console.log(xhr.response);
    return xhr.response;
    }

    }
    }


    And changed the dataSource property in SpreadSheet.vue to getDataFromFile().

    I get a blob back but only 803 bytes (and I know the file is 100kb)

    What am I missing?

    Thanks

  • Marked as Answer

    Replied 29 December 2020, 9:35 pm EST

    Hi,
    If I understand correctly you want to import the file from the path. For this you use excelIO.open method. Please refer to the following code snippetand let us know if you face any issues.

    excelIo.open(
    xhr.response,
    function (json) {
    var workbookObj = json;
    console.log(json);
    spread.fromJSON(workbookObj, {
    doNotRecalculateAfterLoad: true,
    });
    },
    function (e) {
    // process error
    alert(e.errorMessage);
    }
    );


    ExcelIO Demo: https://www.grapecity.com/spreadjs/demos/features/workbook/excel-import-export/vue

    Regards
    Avinash
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels