Datagrid export to Excel losing gridlines

L

LouV

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top