Export the content of the asp.net webpage to word

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.