【发布时间】:2015-03-27 01:52:34
【问题描述】:
我需要将数据从基础网格导出到 excel,我们也在使用 mvc。我得到了代码,但它的作用是遍历每条记录,然后形成 excel,这会导致性能不佳。但我想要的是它应该像我们在 asp.net 中那样立即绑定网格数据。
我浏览了很多网站,包括 Infragistics 一个,但到处都是相同的代码。有什么方法可以实现吗?
下面是正在使用的代码
int i = 1;
foreach (Market item in collection)
{
currentWorksheet.Rows[i].Cells[0].Value = item.gp_name;
currentWorksheet.Rows[i].Cells[1].Value = item.gp_MarketCode;
currentWorksheet.Rows[i].Cells[2].Value = item.gp_CountryName;
currentWorksheet.Rows[i].Cells[3].Value = item.gp_ISOCode;
currentWorksheet.Rows[i].Cells[4].Value = item.gp_EricssonOperationalModelEOM;
currentWorksheet.Rows[i].Cells[5].Value = item.gp_region_name;
i++;
}
Response.Clear();
Response.AppendHeader("content-disposition", "attachement; filename=Market.xlsx");
Response.ContentType = "application/octet-stream";
currentWorkbook.SetCurrentFormat(WorkbookFormat.Excel97To2003);
currentWorkbook.Save(Response.OutputStream);
Response.Flush();
Response.End();
//return RedirectToAction("Index");
}
【问题讨论】:
标签: model-view-controller infragistics