Datagrid export to Excel losing gridlines

Discussion in 'ASP .Net' started by LouV, Nov 25, 2004.

  1. LouV

    LouV Guest

    The code below exports a datagrid from a dataset stored in a session
    variable without a hitch. It prompts the user if they would like to
    open or save the exported spreadsheet. But when the user opens or
    saves the spreadsheet, Excel has turned off the gridlines. The
    gridlines can be restored in the Excel options screen manually. Does
    anyone know of a way to export the spreadsheet and show gridlines
    without the user having to turn them on?

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    Dim x, y As Integer
    Dim sPeriod As String = Session("sPeriod")
    Dim dsBillProjections As New DataSet
    Dim tablerow As Integer =
    dsBillProjections.Tables(0).Rows.Count
    Dim tw As New System.IO.StringWriter
    Dim hw As New System.Web.UI.HtmlTextWriter(tw)

    dsBillProjections = Session("ds3")
    dgBillProjections.DataSource = dsBillProjections
    dgBillProjections.DataBind()

    Response.AddHeader("content-disposition", "inline;
    filename=ProjByTkpr.xls")
    Response.ContentType = "application/vnd.ms-excel"
    Response.Charset = ""
    Response.Write(vbCrLf)

    Me.EnableViewState = False

    'Get the HTML for the control.
    dgBillProjections.RenderControl(hw)

    'add html for totals formulas
    tw.Write("<table><tr><td>TOTALS</td>" & vbCrLf)

    For x = 66 To 72
    tw.Write("<td>=SUM(" & Chr(x) & "3:" & Chr(x) &
    "41)</td>")
    Next x

    tw.Write("</tr></table>")

    'Write the HTML back to the browser.
    Response.Write(tw.ToString())

    'End the response.
    Response.End()
    Response.Close()
    dgBillProjections.Dispose()
    dsBillProjections.Dispose()

    End Sub
     
    LouV, Nov 25, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lars Netzel

    Gridlines in Datagrid problem!

    Lars Netzel, Dec 19, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,652
    =?Utf-8?B?V2ViTWF0cml4?=
    Dec 20, 2004
  2. Rotsey
    Replies:
    2
    Views:
    1,166
    Rotsey
    Dec 3, 2007
  3. Magnus Blomberg

    GridView -> Excel = no gridlines

    Magnus Blomberg, Oct 21, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    223
    Magnus Blomberg
    Oct 21, 2005
  4. how to change colors of gridlines in a datagrid

    , Oct 20, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    779
  5. middletree

    Excel gridlines

    middletree, Jul 6, 2005, in forum: ASP General
    Replies:
    5
    Views:
    135
    middletree
    Jul 7, 2005
Loading...

Share This Page