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;
}
Glen LewisPosted Jul 14, 2014, 4:01 AM
Hi, are you using an excel interop, if you are then first check this out.
If I were you I would reconsider changing a C# code that uses an excel automation on web application because Microsoft does not recommend nor does it support its usage on server side.
I do not have a lot of experience with an excel interop but it does seem to me that you are using it, although few API's I do not recognise...
Nevertheless as an alternative you can also try this .NET assembly which is designed for excel processing.
Here is a C# article about creating an excel file with it.
Also I presume the following will be useful to you, here is how you can export your excel file to the client's browser in ASP.NET.
Rahul PrasadPosted Jul 4, 2014, 3:58 AM
You code seems extremely complicated for me..
As Sumit Jolly said,you'd better using C# managed Excel component to create a Excel file or do any other operations like edit,convert ,print,etc.Google around and you 'll find various useful Excel APIs that could save you days in processing this kind of stuff.Apart from Closed XML,you can also try Spire.Excel.The latter one is avaliable on Codeplex-http://spreadsheet.codeplex.com/
Donwload the trail version and check if the features meet your needs.
Guest UserPosted Jun 30, 2014, 10:28 AM
I say you're bothering you a lot with this mega code. It's giant and becomes unmanageable going forward. It's better if you refactor and leverage Nuget package called Closed XML http://www.nuget.org/packages/ClosedXML/.
It's very handy to use and excel operations are magical.
Sampe code is here:
https://gist.github.com/altrive/8557372
Thanks