Excel to JSON

Posted by: chhavi.sethi on 11 May 2020, 11:44 am EST

  • Posted 11 May 2020, 11:44 am EST

    Hi there,

    I’m curious, whether the Wijmo has a utility to convert Excel to JSON. I want to build a screen where a user will upload an Excel and the data of that Excel will be sent to the server in JSON format.

    I researched about it and got this https://www.grapecity.com/wijmo/docs/Topics/Grid/FlexSheet/FlexSheet-Import-Export. The problem with that solution is, it loads the Excel data in the FlexSheet then it can provide the JSON data by accessing its collectionView.

  • Posted 12 May 2020, 2:14 am EST

    Hi Chhavi,

    There is no direct way to convert excel file to JSON. But your solution is correct. You can use FlexGrid or FlexSheet to import excel and convert it into JSON. You can create a flexgrid on the go without actually displaying it on the DOM.

    There is another issue also. When we import an excel file, a CollectionView is not created because the excel may or may not contain data that can be converted into a CollectionView. So, you will also need to create a JSON manually just by iterating over the rows and columns of the FlexGrid. Please refer to the sample below for reference:

    https://stackblitz.com/edit/angular-dxhfkh

    Regards,

    Ashwin

  • Posted 12 May 2020, 11:34 am EST

    Thanks, Ashwin

    I was investigating it more and got ```

    Workbook

    
    

    const workbook = new Workbook();

    workbook.loadAsync(binaryString, (workbookInstance) => {

    const data = workbookInstance.sheets.map((sheet) => {

    return sheet.rows.map((r) => {

    return r.cells.map((c) => c.value);

    });

    console.log(data);

    });

  • Posted 13 May 2020, 12:14 am EST

    Hi Chhavi,

    Yes, you can also use the Workbook class but I did not provide this solution because FlexGrid was easier to implement.

    But, if this works for you then you may use this solution also.

    ~regards

Need extra support?

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

Learn More

Forum Channels