How to import multiple gridview and repeater to word or Excel

Source: Internet
Author: User

Recently, I found that we may encounter order printing problems when developing an online store. I thought I could just display and print it directly, but I had to download it locally. Finally, I only needed to directly select the control to output it in streaming mode.

The code for importing data to word is as follows:

        protected void Button1_Click(object sender, EventArgs e)        {            StringBuilder sb = new StringBuilder();            StringWriter sw = new StringWriter(sb);            HtmlTextWriter htw = new HtmlTextWriter(sw);            Page page = new Page();            HtmlForm form = new HtmlForm();            GridView1.EnableViewState = false;            rptMlist.EnableViewState = false;            myGridView.EnableViewState = false;            page.EnableEventValidation = false;            page.EnableViewState = false;            // Realiza las inicializaciones de la instancia de la clase Page que requieran los diseñadores RAD.            page.DesignerInitialize();            page.Controls.Add(form);            form.Controls.Add(GridView1);            form.Controls.Add(rptMlist);            form.Controls.Add(myGridView);            page.RenderControl(htw);            Response.Clear();            Response.Buffer = true;            Response.ContentType = "application/vnd.ms-word";             Response.AddHeader("Content-Disposition", "attachment;filename=" + PID + ".doc");            Response.Charset = "UTF-8";            Response.ContentEncoding = Encoding.Default;            Response.Write(sb.ToString());            Response.End();        }

The code is very simple. If you have a better method, you can discuss it.

 

How to import multiple gridview and repeater to word or Excel

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.