Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code which converts Byte code to original string and it works in normal HTML page perfectly,
string sql1 = "SELECT Package FROM Package WHERE ID='1'";
        SqlConnection con1 = new SqlConnection(cls.GetConnectionString());
        SqlCommand cmd1 = new SqlCommand(sql1, con);
        SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
        DataTable dt1 = new DataTable();
        da1.Fill(dt1);
        dt1.Columns.Add("Description");
        foreach (DataRow dr1 in dt1.Rows)
        {
            if (dr1 != null)
            {
                byte[] byt1 = (byte[])dr1[0];
                string str1;
                System.Text.ASCIIEncoding enc1 = new System.Text.ASCIIEncoding();
                str1 = enc1.GetString(byt1);
                dr1[1] = str1;
                description = str1;
               
            }
        }

But i want to write this string into word file in the following way
public void CreateWordFile(DataTable dt)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=Publish.doc");        
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-word ";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView gvTemp = new GridView();
        gvTemp.AllowPaging = false;
        gvTemp.DataSource = dt;
        gvTemp.DataBind();
        gvTemp.RenderControl(hw);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
    }


Now here is output

XML
<p style="margin: 0px; text-align: center;">Header</p> <p style="margin: 0px; text-align: center;">Color <span style="color: #ff0000;">Red</span></p><br /> <p style="margin: 0px; text-align: center;">Heading</p>
<table width="100%" cellspacing="1" border="0" id="table1"> <tbody> <tr> <td> <p align="center">TITLE</p></td> <td width="9">&nbsp;</td></tr> <tr> <td width="11">&nbsp;</td> <td>&nbsp;</td> <td width="9">&nbsp;</td></tr> <tr> <td width="11">&nbsp;</td> <td> <p align="justify"><b>Description</b><br /> Details &amp;.</p></td> <td width="9">&nbsp;</td></tr> <tr> <td width="11">&nbsp;</td> <td>&nbsp;</td> <td width="9">&nbsp;</td></tr> <tr> <td width="11">&nbsp;</td> </tr></tbody></table>
><span style="font-weight: bold;">Color</span></p><span style="font-weight: bold;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Footer</span>




So please guide me how to publish this above in a word file?
Posted

1 solution

I hope you are trying to create a word file from the content of a dataTable.
I suggest you to have a look at some of this articles
creating-word-document-using-c[^]
WordFromDotNet[^]
Creating a Word Document by Passing the Dataset including Image(s)[^]
 
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