Gridview to Excel gridlines missing RRS feed

  • Question

  • I have the following code that exports a gridview.net box from c# to excel  but the gridlines do not show up in the spreadsheet-

    If anyone can help it would be much appreciated - thank-you - Jason.

                 Response.Buffer = true;
                 Response.Charset = "";
                 Response.ContentType = "application / vnd.openxmlformats - officedocument.spreadsheetml.sheet";
                 Response.AddHeader("content-disposition", "attachment;filename=SqlExport.xls");
                 System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                 System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                 GridView1.GridLines = GridLines.Both;

    • Moved by CoolDadTx Thursday, September 12, 2019 1:53 PM ASP.NET related
    Wednesday, September 11, 2019 2:32 PM

All replies

  • Have you asked here https://forums.asp.net/

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Wednesday, September 11, 2019 4:40 PM
  • Hi giasone777,

    Thank you for posting here.

    >> the gridlines do not show up in the spreadsheet

    The code you provided is actually generating an HTML file and deliver it with Excel extension, please refer to this link:

    Asp.net to Excel but no grid / Lines in Excel

    IMHO, you can try a 3rd-party dll, for example, the ClosedXML.

    Please refer to this tutorial: Export Gridview Data to Excel in ASP.NET and you will get your gridlines shown in your excel file.

    Hope it can help you.

    Best Regrads,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 12, 2019 8:20 AM
  • Please post questions related to ASP.NET in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, September 12, 2019 1:53 PM