How can I read an Excel File with JavaScript (without ActiveXObject)

后端 未结 4 808
盖世英雄少女心
盖世英雄少女心 2021-01-04 05:26

My friend asked me to make for a simple application to generate charts (bar, curves) from an Excel file. I opted to use JavaScript as a language since I know already the pow

4条回答
  •  余生分开走
    2021-01-04 06:17

    Here is another perspective on this problem, instead of reading an Excel file with JavaScript, you could directly use JavaScript in Excel with the help of the Funfun Excel add-in. Basically, Funfun is a tool that allows you to use JavaScript in Excel so you could use libraries like Chart.js to plot chart from the data in the spreadsheet.

    Basically, what you need to do is

    1). Insert the Funfun add-in from Office Add-ins store

    2). Create a new Funfun or load a sample from Funfun online editor

    3). Write JavaScrip code as you do in any other JavaScript editor. In this step, in order to directly use the data from the spreadsheet, you need to write some JSON I/O to make Excel cell reference. The place this value is in Setting-short But this would be just several lines. For example, let's assume we have some data like below in the spreadsheet. The Average hours is in cell A1.

    Average hours    Jan    Feb   Mar    Apr
    Baby Jones       93.5   81    94.5   95.5
    Joanne Jones     91.5   90    88.5   85.5
    

    In this case, the JSON I/O value would be:

    {
        "months": "=C6:G6",
        "manager1": "=C7:G7",
        "manager2": "=C8:G8"
    }
    

    You could check the Funfun documentation for more explanation.

    4). Run the code to plot chart

    Here is a sample chart that I made using JavaScript(Chart.js) and Excel data on Funfun online editor. You could check it on the link below. You could also easily load it to your Excel as described in Step2.

    https://www.funfun.io/1/edit/5a365e7c74efa7334ff272a6

    Disclosure: I'm a developer from Funfun.

提交回复
热议问题