Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 25th, 2004, 11:57 AM   #1
see07
Programmer
 
Join Date: Oct 2004
Posts: 37
Rep Power: 0 see07 is on a distinguished road
I have a web form in which I have a datagrid, I need to export this data to a Microsoft Excel sheet.

I’m doing it thus:

Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

DataGrid1.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());
Response.End();

But I'd like to avoid system ask user if desires open or save this file, instead would open excel sheet as another window and when user saves the file it be saved as an excel file.

Does somebody knows how achieve this?

I'll appreciate it very much.
A.L.
__________________
<span style='color:red'>El Hombre que tiene Amigos, debe mostrarse Amigo...</span>
see07 is offline   Reply With Quote
Old Oct 25th, 2004, 5:23 PM   #2
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Not really sure what it is you are trying to do, you could always export to CSV first though, Excel is capable of reading CSV along with a million other spreadsheet applications.
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Oct 26th, 2004, 3:59 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
Generally as a security thing you will not be able to open a file or save a file to a users computer. Its a major security hole if you can...
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote
Old Oct 26th, 2004, 12:21 PM   #4
see07
Programmer
 
Join Date: Oct 2004
Posts: 37
Rep Power: 0 see07 is on a distinguished road
Thanks you Berto.
What is happening is that when user select open file and modify some column of it and then save file, the only way that have to do it is closing application, then systenm ask him if desire to save modifications, if the answer is yes, then ask a name for file and ask type of file. I'd like to have ever a file name, I inserted a line in my code:
Response.AddHeader("Content-Disposition", "inline;filename=Clientes.xls");
to assign a name for file but still is asking for a name when open, modify and then save file.
Do you have a clue that help me?
A.L.
__________________
<span style='color:red'>El Hombre que tiene Amigos, debe mostrarse Amigo...</span>
see07 is offline   Reply With Quote
Old Oct 26th, 2004, 1:30 PM   #5
see07
Programmer
 
Join Date: Oct 2004
Posts: 37
Rep Power: 0 see07 is on a distinguished road
Hello:
I have an answer to display Excel sheet in another form. I only put this code:
<form id = “Form1” method = “post” runat = “server” target = “_blank”>
Where target is that do the entire trick.
In C# I include this line:
Response.AddHeader("Content-Disposition", "inline;filename=Clientes.xls");
When user decides to save the file it is saved with Clientes.xls as name, obviously as Book of Microsoft Excel as type.
But when user decides to open the file and modify some column and then save it, system opens a window “Save As” where ask for file name and save as type. Why is asking about it if I already gave this data? How can I do that system when file is opened, modified and saved it be saved as Clientes.xls?
I’ll thank your help.
A.L.
__________________
<span style='color:red'>El Hombre que tiene Amigos, debe mostrarse Amigo...</span>
see07 is offline   Reply With Quote
Old Oct 27th, 2004, 3:45 AM   #6
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
if the file is being saved through the web browser to a users computer it has to d/l the file generally, (unless web standard files or you cache it or something) but whenever you want to explicitly save a file the user always has the open of saving a file as some random name, or opening the file or jus tsaving it as far as i can remember, and as far as i know you cant override this unless you go into internet explorere exploits.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC