我需要将数据从基础设施网格导出到excel,我们也在使用mvc。我得到了代码,但它所做的是遍历每个记录,然后形成excel,这导致了较差的性能。但我想要的是,它应该像我们在asp.net中所做的那样,立即绑定网格数据
我浏览了很多网站,包括Infrastics,但到处都是相同的代码。有什么办法做到这一点吗?
下面是我现在使用的代码
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");
}
您尝试过使用DataPresenterExcelExporter吗?
DataPresenterExcelExporter exporter = new DataPresenterExcelExporter ();
exporter.Export(Grid, FileName, WorkbookFormat.Excel2007, Exportoptions);