先来个笨点的方法,也可以实现的:
1.页面上按钮点击事件:
$("#ImitationConfirm").click(function () {
//将用户输入的名片信息转成数组,然后转成json格式,最后放到CardInfosJson这个input中,数据格式如下:
//{"name":"Sheet1","frozenRowCount":1,"data":{"dataTable":{"0":{"0":{"value":"姓名"},"1":{"value":"职位"},"2":{"value":"公司名称"},"3":{"value":"公司地址"},"4":{"value":"电话"},"5":{"value":"传真"},"6":{"value":"手机号码"},"7":{"value":"邮箱"},"8":{"value":"备注"}}}}}
var spread1 = $("#ss").wijspread("spread");
var sheet = spread1.getActiveSheet();
var dirtyItems = new Array();
for (var i = 0; i < 21; i++) {
dirtyItems = new Array();
for (var j = 0; j < 9; j++) {
dirtyItems[j] = sheet.getValue(i,j);
}
}
var jsonSheet = JSON.stringify(dirtyItems);
$("#CardInfosJson").attr("value", jsonSheet.toString());
$("#CompleteImitationDesign").submit();
});
2.在服务器端的Controller对应的处理方法中:
string[][] myDataTable = JsonConvert.DeserializeObject<string[][]>(CardInfosJson);
for (int i = 1; i < myDataTable.Length; i++)
{
if (myDataTable[0] != null || myDataTable[1] != null || myDataTable[2] != null ||
myDataTable[3] != null || myDataTable[4] != null || myDataTable[5] != null ||
myDataTable[6] != null || myDataTable[7] != null || myDataTable[8] != null)
{
cardInfo2 = new CardInfo
{
Name = myDataTable[0],
Position = myDataTable[1],
CompanyName = myDataTable[2],
CompanyAddress = myDataTable[3],
TelPhone = myDataTable[4],
Fax = myDataTable[5],
Phone = myDataTable[6],
Email = myDataTable[7],
Remarks = myDataTable[8],
Template = template
};
//存入数据库
unitOfWork.CardInfoRepository.Insert(cardInfo2);
unitOfWork.Save();
}
}
3.我就是通过上面的方法实现Spread Excel从客户端向数据库端传值的,由于用户输入的行数不定,所以判断空值的
任务就很大。
4.我有一个问题:就是在客户端,经过用户编辑之后,sheet对象如何取到有数据的Excel的行数和列数呢?
我看到sheet有一个方法,这个方法就是sheet.getdirtyRows(),这个名字是取到脏的行数,这个脏的,就是用户
修改过的吗? |