473,411 Members | 2,164 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,411 software developers and data experts.

Saving datagrid as Excel file

RSH
Hi,

Im using the code below to render a datagrid as an Excel file. It seems to
work fine when the user clicks on the Save button. But when they click on
the open button, it renders correctly but when the user attempts to save the
document from the browser...it saves it as an HTML file. Is there any way
to disable the Open button and force the user to save the file? Or some
other trick to make sure the file saves as a type xls?

Response.Clear()

Response.Buffer = True

Response.ContentType = "application/vnd.ms-excel"

Response.Charset = ""

Response.AddHeader("Content-Disposition",
"attachment;filename=ClientAlertExport" & Now() & ".xls")

Dim SW As System.IO.StringWriter = New System.IO.StringWriter

Dim HTW As System.Web.UI.HtmlTextWriter = New
System.Web.UI.HtmlTextWriter(SW)

DataGrid1.RenderControl(HTW)

Response.Write(SW.ToString())

Response.End()

Thanks,

Ron
Jun 5 '07 #1
1 1323
It's because you're writing to the disk with HTML
check out this code sample:
http://www.aspnet101.com/aspnet101/a...=ExportDGExcel

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com

"RSH" <wa*************@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi,

Im using the code below to render a datagrid as an Excel file. It seems
to work fine when the user clicks on the Save button. But when they click
on the open button, it renders correctly but when the user attempts to
save the document from the browser...it saves it as an HTML file. Is
there any way to disable the Open button and force the user to save the
file? Or some other trick to make sure the file saves as a type xls?

Response.Clear()

Response.Buffer = True

Response.ContentType = "application/vnd.ms-excel"

Response.Charset = ""

Response.AddHeader("Content-Disposition",
"attachment;filename=ClientAlertExport" & Now() & ".xls")

Dim SW As System.IO.StringWriter = New System.IO.StringWriter

Dim HTW As System.Web.UI.HtmlTextWriter = New
System.Web.UI.HtmlTextWriter(SW)

DataGrid1.RenderControl(HTW)

Response.Write(SW.ToString())

Response.End()

Thanks,

Ron


Jun 5 '07 #2

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

Similar topics

3
by: Vikram | last post by:
Hi, Given below is my task. An user can open the xls file from my website (loaded on the top frame). After filling the Excel, he can click a send button at the bottom frame. By clicking the...
0
by: mathieu cupryk | last post by:
in the Button1_Click I need to make the 1st column saved as readonly. How can I do this? using System; using System.Collections; using System.ComponentModel; using System.Data; using...
2
by: Steve Chatham | last post by:
I use the following code: Private Sub RbtnExport_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RbtnExport.SelectedIndexChanged Dim sFile As String =...
0
by: Luis Esteban Valencia | last post by:
in the Button1_Click I need to make the 1st column saved as readonly. How can I do this? using System; using System.Collections; using System.ComponentModel; using System.Data; using...
0
by: Speilman_54 | last post by:
Hi, I'm converting an excel Macro into visual basic 2005 express, as I don't have a copy of VB 6 and trying to make and executable from it, I know this version doesn't have the save file as .exe,...
6
by: Karl | last post by:
Hi all, It may seem like a rather odd request (or not) but I would like to be able to create a file (doc, jpg, xls or one of many other files that can be automated) on a website and stream it to...
2
by: RobcPettit | last post by:
Hi, I need some advice on how to proceed with saving gridview contents. Ive got a 'datagridview control' on a form, so its window application only not web. I fill this programatically with...
6
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.