# Excel数据导入数据网格（仅支持IE）

示例：表单数据网格设计，原料名称、规格、数量、单价、金额的标题列分别对应标识ylmcList、ggList、slList、djList、jeList

![](/files/-Lp_wFmxOK3oo2kFSPJk)

Excel样式如下：

![需要导入的数据](/files/-Lp_wMAAuZF9RWmOrZEq)

示例代码：

```
var filePath="D:\\mytest.xls"; //要读取的xls
var sheet_id=1; //读取第1个表
var row_start=2; //从第1行开始读取
var tempStr='';
try{
    var oXL = new ActiveXObject("Excel.application"); //创建Excel.Application对象
}catch(err)
{
    alert("错误："+err);
}
var oWB = oXL.Workbooks.open(filePath);
oWB.worksheets(sheet_id).select();
var oSheet = oWB.ActiveSheet;
var colcount=oXL.Worksheets(sheet_id).UsedRange.Cells.Rows.Count ;//总共多少条数据

this.form.get("yllb").setData({});//先把原料列表清空
var data=new Array();

//拼装数据网格的data数据

for(var i=row_start;i<=colcount;i++){
    op = {
        "ylmcList":{"ylmc":oSheet.Cells(i,1).value},
        "ggList":{"gg":oSheet.Cells(i,2).value},
        "slList":{"sl":oSheet.Cells(i,3).value},
        "djList":{"dj":oSheet.Cells(i,4).value},
        "jeList":{"je":oSheet.Cells(i,5).value}
    };
    data[i-2]=op;
}
op2 = {
    "data":data,
    "total":{}
};
this.form.get("yllb").setData(op2);//给数据网格赋值
alert("导入完成！");
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://o2oa.gitbook.io/course/liu-cheng-guan-li/liu-cheng-ying-yong-kai-fa-yu-she-ji/excel-shu-ju-dao-ru-shu-ju-wang-ge-jin-zhi-chi-ie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
