【问题标题】:Import a table from an Excel Sheet into HTML table , using AngularJS使用 AngularJS 将表格从 Excel 工作表导入 HTML 表格
【发布时间】:2016-10-15 02:35:22
【问题描述】:

如何将 Excel 工作表导入 HTML 表格,以便根据列名将每一行转换为对象。 使用 Angular JS

P.S:未来的排序表需要对象。

【问题讨论】:

标签: angularjs html user-interface


【解决方案1】:

我为此开发了一个组件。如果对你有帮助请看一下:https://github.com/Helvio88/angular-xlsx-model

使用

<input type="file" xlsx-model="excel">

将使您能够选择文件。
对于多个文件:

<input type="file" xlsx-model="excel" multiple> 

它可以进一步扩展以过滤掉特定的扩展等等。参考http://www.w3schools.com/jsref/dom_obj_fileupload.asp

一旦您选择了一个文件,一个以 xlsx-model 属性命名的 Angular JSON 对象(在本例中为“excel”)将以这种格式创建:

$scope.excel(多个文件):

{
    "file1.xlsx": {
        "Sheet1": [
            {
                "Col1Name": "Row1Col1_Value",
                "Col2Name": "Row1Col2_Value"
            },
            {
                "Col1Name": "Row2Col1_Value",
                "Col2Name": "Row2Col2_Value"
            }
        ],
        "Sheet2" : [...]
    },
    "file2.xlsx": {...}
}

如果您选择了多个文件,则该模型有效。对于单个文件,情况略有不同。
$scope.excel(单个文件):

{
    "Sheet1": [
        {
            "Col1Name": "Row1Col1_Value",
            "Col2Name": "Row1Col2_Value"
        },
        {
            "Col1Name": "Row2Col1_Value",
            "Col2Name": "Row2Col2_Value"
        }
    ],
    "Sheet2" : [...]
}

游乐场: http://plnkr.co/edit/inETA0PcxIkm4EmS9qjD?p=preview

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    • 2018-09-30
    • 2013-10-23
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    相关资源
    最近更新 更多