473,811 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Conten tType = "applicatio n/vnd.ms-excel"

Response.Charse t = ""

Response.AddHea der("Content-Disposition",
"attachment;fil ename=ClientAle rtExport" & Now() & ".xls")

Dim SW As System.IO.Strin gWriter = New System.IO.Strin gWriter

Dim HTW As System.Web.UI.H tmlTextWriter = New
System.Web.UI.H tmlTextWriter(S W)

DataGrid1.Rende rControl(HTW)

Response.Write( SW.ToString())

Response.End()

Thanks,

Ron
Jun 5 '07 #1
1 1337
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.comwrot e in message
news:%2******** ********@TK2MSF TNGP03.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.Conten tType = "applicatio n/vnd.ms-excel"

Response.Charse t = ""

Response.AddHea der("Content-Disposition",
"attachment;fil ename=ClientAle rtExport" & Now() & ".xls")

Dim SW As System.IO.Strin gWriter = New System.IO.Strin gWriter

Dim HTW As System.Web.UI.H tmlTextWriter = New
System.Web.UI.H tmlTextWriter(S W)

DataGrid1.Rende rControl(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
12382
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 button i have to save the file in a shared directory on the web server by a unique name. Is it possible ?
0
1309
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 System.Drawing; using System.Web;
2
2482
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 = Session("User") & "-Customer List-" & Today() sFile = sFile.Replace("/", "") RbtnExport.Visible = False Select Case RbtnExport.SelectedItem.Value Case "Excel" Response.ContentType = "application/x-msexcel"
0
1159
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 System.Drawing; using System.Web;
0
2026
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, but I have a 3rd party software that will convert vb projects into .exe files. My issue is in the the saving of the excel file. The macro bassicly imports a tab delimeted file and manipulates the file and then saves it, as a template to work...
6
3370
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 a user without saving it to the disk first. Obviously saving the file first and streaming it afterwards is fairly easy to do, but it relies on disk write permissions on the server and you'd have to make sure the file was removed afterwards.
2
1959
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 'dataGridView1.Rows.Add(whatever array)' so its not bound to a database. Once the data in I want to save the data in a format that I can 1,reuse in the datagrid or 2, as an excel file. From what Ive googled so far, this doesnt seem possible without...
6
8072
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 to change the Content- Type and Content-Disposition headers, and essentially print the same report, and it's done. That works fine. But in some reports on the web I need to show images. The web part is fine, but I'm having a tough time...
6
2741
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 the event handler for a form button. Is there other ways to accomplish this? I looked at some on the web and usergroups, but was confused as to the functioning. BTW my datagrid is enclosed in a <div></divfor ease of scrolling if that would...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6893
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.