Reference: http://topic.csdn.net/t/20040909/15/3356495.html
After the webpage content is exported to word, the display mode of the content is changed:
Public void toword (system. Web. UI. Control CTL)
{
Httpcontext. Current. response. Clear ();
Httpcontext. Current. response. charset = "";
Httpcontext. Current. response. appendheader ("content-disposition", "attachment?filename=doclibrary.doc ");
Httpcontext. Current. response. contentencoding = system. Text. encoding. getencoding ("gb2312 ");
// Change the contenttype value to MS-word to export to word.
Httpcontext. Current. response. contenttype = "application/MS-word"; // image/JPEG; text/html; image/GIF; VND. MS-Excel/MSWord
CTL. Page. enableviewstate = false;
System. Io. stringwriter Tw = new system. Io. stringwriter ();
System. Web. UI. htmltextwriter hW = new system. Web. UI. htmltextwriter (TW );
Ctl. RenderControl (hw );
HttpContext. Current. Response. Write (tw. ToString ());
HttpContext. Current. Response. End ();
}
Call method: ToWord (this. divTest); // Note: divTest is the Control id.