Click here to Skip to main content
15,885,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
Now i have a gridview that contains some of phone numbers and user name and i want to make a button to save that data into word file in the pc of user. How can i make this, please?
Thanks
Posted
Updated 12-Jan-11 8:43am
v2
Comments
TweakBird 12-Jan-11 14:44pm    
Can you post your tried sample code here. are you googled for it.?
moon2011 13-Jan-11 4:14am    
Response.Clear();

Response.Buffer = true;

Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.doc");

Response.Charset = "";

Response.ContentType = "application/vnd.ms-word ";

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

GridView1.AllowPaging = false;

GridView1.DataBind();

GridView1.RenderControl(hw);

Response.Output.Write(sw.ToString());

Response.Flush();

Response.End();


there is the code i tried , bur the problem is when i opened the file i found it empty and often it connot be opened because there was an error in encoding, any help, please?

If an Office 2007 version is okay, then using the Open XML Tool[^] is probably the most fun way to do it.

Basically, create the Word doc as you would like it to appear, then create the class that will generate it, looping through your data result and put the values in the appropriate place in the doc.


Not easy, but well worth the effort, especially if you want to spit out the result from a web server...which pretty much precludes using any sort of Office "automation".
 
Share this answer
 
Hi,

Just am googled with 'export gridview to word' as keyword. I got 254K results. below URL is Second one, if you noticed Third result from CP.

Export-GridView-To-Word-Excel-PDF-CSV-Formats-in-ASP.Net[^]

My suggestion is: Please search it before asking the question.
 
Share this answer
 
Comments
GenJerDan 12-Jan-11 15:40pm    
While they (all the ones I checked, anyway) will work, they don't actually create a Word doc. They just "trick" Word or Excel into opening what you send it. That is probably fine in most cases...but not if you need a "real" doc for whetever reason (formatting, etc.).
moon2011 13-Jan-11 3:34am    
thanks for your reply, but i searched for that i had an error occured in opening word file , and i asked for help by another code.
thanks
moon2011 16-Jan-11 4:39am    
Thanks alot , i have solved it
TweakBird 16-Jan-11 4:46am    
Welcome Monamoona!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900