Problem writing HTML content to a Word document in ASP.NET

I am trying to export the contents of an HTML page in Word.

My HTML display page:

  • What is your favorite color?

NA

  1. A list of the top three schools?

one national two devs three ps

And a button for the click event. A button press event will open the word MS and paste the contents of the page into the word.

The text page contains the html design page table property. This only happens in Word 2003. But in 2007, the word document contains text with an out table attribute. How to remove table property in word 2003.

I can not add snapshots. I will also make it clear to you.

I am designing an aspx webpage. I export the contents of the web page using the following code.

protected void Button1_Click(object sender, EventArgs e)
{

    Response.ContentEncoding = System.Text.Encoding.UTF7;
    System.Text.StringBuilder SB = new System.Text.StringBuilder();
    System.IO.StringWriter SW = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlTW = new System.Web.UI.HtmlTextWriter(SW);
    tbl.RenderControl(htmlTW);
    string strBody = "<html>" +
        "<body>" + "<div><b>" + htmlTW.InnerWriter.ToString() + "</b></div>" +
        "</body>" +
        "</html>";

    Response.AppendHeader("Content-Type", "application/msword");
    Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName);
    Response.ContentEncoding = System.Text.Encoding.UTF7;

    string fileName1 = "C://Temp/Excel" + DateTime.Now.Millisecond.ToString();
    BinaryWriter writer = new BinaryWriter(File.Open(fileName1, FileMode.Create));
    writer.Write(strBody);
    writer.Close();
    FileStream fs = new FileStream(fileName1, FileMode.Open, FileAccess.Read);
    byte[] renderedBytes;
    // Create a byte array of file stream length 
    renderedBytes = new byte[fs.Length];
    //Read block of bytes from stream into the byte array 
    fs.Read(renderedBytes, 0, System.Convert.ToInt32(fs.Length));
    //Close the File Stream 
    fs.Close();
    FileInfo TheFile = new FileInfo(fileName1);
    if (TheFile.Exists)
    {
        File.Delete(fileName1);
    }
    Response.BinaryWrite(renderedBytes);

    Response.Flush();
    Response.End();
}
+5
4

HTML, , "application/msword", .

"" .

(X) HTML WordML-, docx4j-ImportXHTML.NET . : ; , StackOverflow.

Word altChunk, :

  • , ;
  • AltChunk Word 2003 ( ).
+1

, , ms-ms Word 2003 2007 .

html ms. , .

Office Interop (Microsoft.Office.Interop.Word) DocX nuget. , "# create word doc".

0

All Articles