using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebAPIServer.Models { [Serializable] public class Product { public int ProductID { get; set; } public string Name { get; set; } public string Description { get; set; } public decimal Price { get; set; } public string Category { get; set; } public static void SaveAsXlS(string fileName, DataTable dataTable) { DataGrid grid = new DataGrid(); DataSet set = new DataSet(); dataTable.TableName = fileName; set.Tables.Add(dataTable.Copy()); grid.HeaderStyle.Font.Bold = true; grid.DataSource = set; grid.DataMember = set.Tables[dataTable.TableName].TableName; grid.DataBind(); using (StreamWriter sw = new StreamWriter(fileName)) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { grid.RenderControl(hw); } } } } }