473,508 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StreamWriter and export to excel

Hi guys
i tried this example at
http://www.codeproject.com/dotnet/ExportToExcel.asp

but
i add these statements below

HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" +
fileName + "\""); //filenam koddan geliyor
response.Write(excelDoc);

when run the page it appear file save window and i save the file but the
file contains only "System.IO.StreamWriter"

i write below code to est data is created or not created in excel file

excelDoc = new System.IO.StreamWriter("c:\deneme.xml", true,
System.Text.Encoding.Default);

and i see that data is true and written in excel

i think that is the problem how i can write
Response.Write(excelDoc.ToString()); I'm sure this
row(Response.Write(excelDoc.ToString()); ) is not correct.
so my question is how can i write StreamWriter to web page to save file as
excel...

Thank you for helping....


Jun 3 '06 #1
2 32706
Hi,

Try changing the stream writer so it is writing to the pages output
stream.

eg

//get response, set content type.
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" +
fileName + "\"");
response.Clear();
excelDoc = new System.IO.StreamWriter(response.OutputStream);

//code to write all the excel stuff, as per the article.
//...
//eg:
excelDoc.Write("This will appear in the file.");
//...

//flush and finish response
excelDoc.Flush();
response.End();

hth -Mike

Serkan wrote:
Hi guys
i tried this example at
http://www.codeproject.com/dotnet/ExportToExcel.asp

but
i add these statements below

HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" +
fileName + "\""); //filenam koddan geliyor
response.Write(excelDoc);

when run the page it appear file save window and i save the file but the
file contains only "System.IO.StreamWriter"

i write below code to est data is created or not created in excel file

excelDoc = new System.IO.StreamWriter("c:\deneme.xml", true,
System.Text.Encoding.Default);

and i see that data is true and written in excel

i think that is the problem how i can write
Response.Write(excelDoc.ToString()); I'm sure this
row(Response.Write(excelDoc.ToString()); ) is not correct.
so my question is how can i write StreamWriter to web page to save file as
excel...

Thank you for helping....


Jun 3 '06 #2
thank you for helping...

"Michael Stancombe" <mi***************@gmail.com> wrote in message
news:11********************@i40g2000cwc.googlegrou ps.com...
Hi,

Try changing the stream writer so it is writing to the pages output
stream.

eg

//get response, set content type.
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" +
fileName + "\"");
response.Clear();
excelDoc = new System.IO.StreamWriter(response.OutputStream);

//code to write all the excel stuff, as per the article.
//...
//eg:
excelDoc.Write("This will appear in the file.");
//...

//flush and finish response
excelDoc.Flush();
response.End();

hth -Mike

Serkan wrote:
Hi guys
i tried this example at
http://www.codeproject.com/dotnet/ExportToExcel.asp

but
i add these statements below

HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" +
fileName + "\""); //filenam koddan geliyor
response.Write(excelDoc);

when run the page it appear file save window and i save the file but the
file contains only "System.IO.StreamWriter"

i write below code to est data is created or not created in excel file

excelDoc = new System.IO.StreamWriter("c:\deneme.xml", true,
System.Text.Encoding.Default);

and i see that data is true and written in excel

i think that is the problem how i can write
Response.Write(excelDoc.ToString()); I'm sure this
row(Response.Write(excelDoc.ToString()); ) is not correct.
so my question is how can i write StreamWriter to web page to save file
as
excel...

Thank you for helping....

Jun 3 '06 #3

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

Similar topics

1
5348
by: congngo | last post by:
Hi all Every time I export a table into an excel spreadsheet. It has a leading apostrophe on every cells. This drive me nut. I have to do a work around by export table into a txt file than...
5
2651
by: Tim Frawley | last post by:
I created a .NET Com Class object for use in ASP reports to export database results directly to Excel. I have it all working just find but I cannot get the Excel process to go away after the job...
3
2579
by: ABC | last post by:
What methods can export excel file from stored procedure with parameters which input from web form?
1
3038
by: panku007 | last post by:
hi All, I wanted to export excel data into ms word document through java coding.So please send me reply,according to my question. thanks
2
1847
by: tbenchakroune | last post by:
How can I export Excel spreadsheets to Access db? Thanks, T.
1
2842
by: san1014 | last post by:
Hi How to import and export excel data into oracle database using java. Thank you
1
6180
by: CF FAN | last post by:
Can Report Builder Export Excel Files with multiple Sheets How can I create a report that it can export in excel by multiple
3
3015
by: minhtran | last post by:
Hi all Anyone has any idea how to get a Excel header column in VB.NET. Please, help me. Thank you so much in advance
0
2498
by: Dubois | last post by:
Bonjour Lorsque je lance un export excel au travert d'une page en ASP.NET C#, cela fonctionne sur la machine de développement, par contre, sur le serveur de production j'ai l'erreur suivante : ...
3
4052
by: prashantdixit | last post by:
Hi, I am trying to export excel data to text file in a particular format. The Format for each ROW of Excel is like IMAN_ROOT/bin/import_file -f=<Column A> -type=<Column B> -d=<Column C>...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
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...
0
7336
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,...
0
7401
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...
1
7063
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...
1
5059
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
4720
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...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.