我需要将数据从infragistics网格导出到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");
}
答案 0 :(得分:0)
您是否尝试过使用DataPresenterExcelExporter?
DataPresenterExcelExporter exporter = new DataPresenterExcelExporter ();
exporter.Export(Grid, FileName, WorkbookFormat.Excel2007, Exportoptions);