【发布时间】:2016-10-15 02:35:22
【问题描述】:
如何将 Excel 工作表导入 HTML 表格,以便根据列名将每一行转换为对象。 使用 Angular JS
P.S:未来的排序表需要对象。
【问题讨论】:
标签: angularjs html user-interface
如何将 Excel 工作表导入 HTML 表格,以便根据列名将每一行转换为对象。 使用 Angular JS
P.S:未来的排序表需要对象。
【问题讨论】:
标签: angularjs html user-interface
我为此开发了一个组件。如果对你有帮助请看一下: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" : [...]
}
【讨论】: