Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Datagrid export to Excel losing gridlines

Reply
Thread Tools

Datagrid export to Excel losing gridlines

 
 
LouV
Guest
Posts: n/a
 
      11-25-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid as grid lines when Gridlines set to none. Rotsey ASP .Net 2 12-03-2007 04:53 AM
how to change colors of gridlines in a datagrid jkwasson@nospam.nospam ASP .Net Datagrid Control 0 10-20-2006 06:41 PM
GridView -> Excel = no gridlines Magnus Blomberg ASP .Net Datagrid Control 0 10-21-2005 04:33 PM
Excel gridlines middletree ASP General 5 07-07-2005 01:26 PM
Gridlines in Datagrid problem! Lars Netzel ASP .Net 3 12-20-2004 06:23 PM



Advertisments