Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to export data into MS-Word document using C# coding.
In detail-I want to create new word document and export data like logo,disclaimer
and other data at specific location of word doc.
I not found as such any example.
Pls.,can anybody help...
Any solution,link,hint and suggestion is welcome..

Thanks in advance..
Posted
Comments
devbtl 13-Jan-12 6:21am    
please search in codeproject first then ask here. There are lot of question and solved answer of your question. Thanks

You should always start with the MSDN references. They always have pretty good examples that you can generally alter to fit what you want. Office Interop How To[^] should get you started.
 
Share this answer
 
This example may help you.

In your case instead of taking data from database just make a datatable at your end with your required data.
protected void ExportToWord()
{
    //Get the data from database into datatable
    string strQuery = "select CustomerID, ContactName, City, PostalCode" +
                      " from customers";
    SqlCommand cmd = new SqlCommand(strQuery);
    DataTable dt = GetData(cmd);
 
    //Create a dummy GridView
    GridView GridView1 = new GridView();
    GridView1.AllowPaging = false;
    GridView1.DataSource = dt;
    GridView1.DataBind();
 
    Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition",
        "attachment;filename=DataTable.doc");
    Response.Charset = "";
    Response.ContentType = "application/vnd.ms-word ";
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView1.RenderControl(hw);
    Response.Output.Write(sw.ToString());
    Response.Flush();
    Response.End();
}
 
Share this answer
 
v2
Comments
Manisha Tambade 13-Jan-12 6:46am    
hi,Thanks,i think in case of data i will able to do by this but what about Image.
Means i want to transfer image at specific location like left corner of word doc.
i want to read specific location of word doc is it possible like Excel?
prasenjeit 13-Jan-12 6:59am    
Hi, I haven't tried this myself before but this chain may help you.

http://social.msdn.microsoft.com/forums/en-US/vsto/thread/5d68fa72-3fd2-49ca-bf4b-dce4c2899839/
Manisha Tambade 13-Jan-12 7:18am    
i think this will help.Thanks..
Hi,
Get the best example from this link;Click Here[^]
 
Share this answer
 

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