473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Datagrid export to Excel losing gridlines

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
Nov 18 '05 #1
0 1724

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
1
by: RSB | last post by:
Hi Everyone, i am using the following code to transfer a DataGrid to Excel File. Every thing works ok beside the long numerice value like 0000121900000000 gets converted to 1.219E+11. how can i...
1
by: Luis Esteban Valencia | last post by:
Here is my aspx code: ============= <%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="PDM.excel.WebForm3" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0...
5
by: tshad | last post by:
I have been trying to figure out what the Datagrid is doing to create its formatting. I found that some of my Datagrids have a 3D type of border and sometime it has a straight line. I finally...
3
by: Bidarkota | last post by:
When i export DataGrid to Excel all the HTML contents are also exporting to excel. i am using stylesheets in the ASPX Page and i am getting an alert message that stylesheets are missing. i need to...
0
by: kieran | last post by:
Hi, I have an 'export to excel' button on my Datagrid. All works well except that on my Datagrid, I have sub total rows. The subtotal rows use colspan so that the subtotals are given above...
6
by: Sridhar | last post by:
Hi, I have to export data inside the datagrid into an excel worksheet. I have to do this on button click event. I am trying to do like this. First get the DataTable from the datagrid and...
6
by: slinky | last post by:
I found the following code to transfer datagrid data to an Excel file. Is this written in C#?... I'm a vb.netter. I'm just not sure where to place the code to experiment on it. Should I place it in...
3
by: ulai | last post by:
Thanks for your help. It really help to solve my work. But now i have a bigger problem : I had more than 65535 records in gridview divide by 10/pages. And when i tried to export the gridview in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.