3
Answers

creating an excel sheet using C#

this is the code that i used to create an excel sheet using c# but no file\s are created how can i rectify ir               
protected void GenerateWorksheetSheet1(WorksheetCollection sheets)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvDeatails.AllowPaging = false;
Worksheet sheet = sheets.Add("NTEOver500");
sheet.Table.DefaultRowHeight = 14.25F;
sheet.Table.DefaultColumnWidth = 54F;
sheet.Table.ExpandedColumnCount = 25;
sheet.Table.ExpandedRowCount = 4000;
sheet.Table.FullColumns = 1;
sheet.Table.FullRows = 1;
sheet.Table.Columns.Add(83);
sheet.Table.Columns.Add(72);
sheet.Table.Columns.Add(73);
WorksheetColumn column3 = sheet.Table.Columns.Add();
column3.Width = 69;
column3.Span = 1;
WorksheetColumn column4 = sheet.Table.Columns.Add();
column4.Index = 6;
column4.Width = 86;
WorksheetRow Row0 = sheet.Table.Rows.Add();
WorksheetCell cell;
cell = Row0.Cells.Add();
cell.Data.Type = DataType.String;
cell.Data.Text = "UserID";
cell = Row0.Cells.Add();
cell.Data.Type = DataType.String;
cell.Data.Text = "UserName";
cell = Row0.Cells.Add();
cell.Data.Type = DataType.String;
cell.Data.Text = "Education";
cell = Row0.Cells.Add();
cell.Data.Type = DataType.String;
cell.Data.Text = "Location";
sheet.Options.Selected = true;
sheet.Options.ProtectObjects = false;
sheet.Options.ProtectScenarios = false;
sheet.Options.PageSetup.Header.Margin = 0.3F;
sheet.Options.PageSetup.Footer.Margin = 0.3F;
sheet.Options.PageSetup.PageMargins.Bottom = 0.75F;
sheet.Options.PageSetup.PageMargins.Left = 0.7F;
sheet.Options.PageSetup.PageMargins.Right = 0.7F;
sheet.Options.PageSetup.PageMargins.Top = 0.75F;
}

Answers (3)