Click here to Skip to main content
11,412,578 members (70,544 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hello

I am using a code for download attached excel file.
After download this excel file Gridline of excel is automatically false.
Means Excel gridline not showing.

my code:-

Response.Clear();
            System.IO.StringWriter tw = new System.IO.StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            
            Response.ContentType = "application/msexcel";
            //Response.AddHeader("Content-disposition", "attachment;filename=MyFiles.xls");
            Response.AddHeader("Content-disposition", string.Format("attachment;filename=MyFiles.xls; Gridlines=true"));
            
 
            using (StringWriter sw = new StringWriter())
            {
                using (HtmlTextWriter htw = new HtmlTextWriter(sw))
                {
                    Table table = new Table();
 
                    //  include the gridline settings
                    table.GridLines = gv.GridLines;
 
                    //  add the header row to the table
                    if (gv.HeaderRow != null)
                    {
                        table.Rows.Add(gv.HeaderRow);
                    }
                    foreach (GridViewRow row in gv.Rows)
                    {
                        table.Rows.Add(row);
                    }
                    table.RenderControl(htw);                   
                    HttpContext.Current.Response.Write(sw.ToString());
                    HttpContext.Current.Response.End();
                }
            }

please help
Posted 29-Mar-13 3:54am
Edited 29-Mar-13 14:02pm
Maciej Los177.9K
v4

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

//Try this
 Table table = new Table();
            table.BorderStyle = BorderStyle.Solid;
            table.BorderWidth=new Unit(1);
            table.BorderColor = System.Drawing.Color.Black;
            table.GridLines = GridLines.Both;

//You can also render the GridView directly
  Permalink  
Comments
Rakesh Tailor at 29-Mar-13 9:17am
   
thanks for support.
But this code is for lines between data not for all gridlines in excel sheet.
I want to show gridline in whole sheet.
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 364
1 Sascha Lefévre 200
2 Maciej Los 135
3 ProgramFOX 130
4 Sergey Alexandrovich Kryukov 110
0 Sergey Alexandrovich Kryukov 9,025
1 OriginalGriff 7,247
2 Maciej Los 3,525
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150427.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100