private void GenerateExcel(FASTWeb.Models.ModularReport reportData, string fileName) { StringBuilder gridHtml = new StringBuilder(); gridHtml.Append("<Table>"); gridHtml.Append("<thead>"); foreach (FASTWeb.Models.ReportColumn column in reportData.Columns) { gridHtml.Append(String.Format("<th>{0}</th>", column.Content)); } gridHtml.Append("</thead>"); gridHtml.Append("<tbody>"); foreach (FASTWeb.Models.ReportData data in reportData.Data) { gridHtml.Append("<tr>"); foreach (FASTWeb.Models.ReportColumn column in data.DataList) { gridHtml.Append(String.Format("<td>{0}</td>", column.Content)); } gridHtml.Append("</tr>"); } gridHtml.Append("</tbody>"); gridHtml.Append("</Table>"); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=" + fileName); Response.ContentType = "application/xls"; Response.Write(gridHtml.ToString()); Response.End(); }
public void ExportAssetSearchResult() { List <vwFixAssetList> list = (List <vwFixAssetList>)TempData["Assets"]; TempData["Assets"] = list; FASTWeb.Models.ModularReport reportData = GenerateAssetReportData(list); GenerateExcel(reportData, "ListOfAssets.xls"); }
public void ExportEmployeeSearchResult() { List <vwEmployeeList> list = (List <vwEmployeeList>)TempData["Employees"]; TempData["Employees"] = list; FASTWeb.Models.ModularReport reportData = GenerateEmployeesReportData(list); GenerateExcel(reportData, "ListOfEmployees.xls"); }