About data filtering after Excel export download

Source: Internet
Author: User

2016.5.11

Two ways:

Foreground filter

1. generate file stream download

① Backstage Accept Form form, stitching SQL

         Public voidDown (Studenti I,intStatus =0) {List<string> ls =Newlist<string>(); List<SqlParameter> LP =NewList<sqlparameter>(); if(I.recommname! =NULL) {ls. ADD ("[email protected]"); Lp. ADD (NewSqlParameter ("@Recomm", I.recomm)); }            if(I.datetime! =0) {ls. ADD ("[email protected]"); Lp. ADD (NewSqlParameter ("@DateTime", I.datetime)); }            ///range of ValuesDownbll.downstudeni (LS, LP. ToArray (),"Trainee Management"); }
View Code

② using SQL to query out a DataTable

         Public Static voidDownstudeni (list<string> name, sqlparameter[] parameter,stringTitle) {            stringsql ="SELECT * from Studenti where"; foreach(varIinchname) SQL+ = i +" and"; SQL+="0=0"; DataTable DT=SD.            Search (sql, parameter);        Excelhelper.createexceltodown (DT, Title); }
View Code

③ uses Nopi to write files

        /// <summary>        ///table into Excel and download/// </summary>        /// <param name= "DT" >Table</param>        /// <param name= "title" >file name</param>         Public Static voidCreateexceltodown (DataTable DT,stringtitle) {            using(Workbook book =NewHssfworkbook ()) {Sheet Sheet= Book. Createsheet ("Sheet1"); Row HeaderRow= Sheet. CreateRow (0); CellStyle style=Book .                Createcellstyle (); Style. Alignment=HorizontalAlignment.Center; //1. Conversion table Header                 for(inti =0; i < dt. Columns.count; i++) {cell cell=HeaderRow.                    Createcell (i); Cell. CellStyle=style; Cell. Setcellvalue (dt. Columns[i].                ColumnName); }                //2. Fill in the data                intRowlen =dt.                Rows.Count; intCollen =dt.                Columns.count;  for(inti =0; i < Rowlen; i++) {DataRow Dr=dt.                    Rows[i]; Row R= Sheet. CreateRow ((i+1));  for(intj =0; J < Collen; J + +) {R.createcell (j). Setcellvalue (Dr[j].                    ToString ()); }                }                //3. Download                using(MemoryStream ms =NewMemoryStream ()) {Book.                    Write (MS); HttpContext.Current.Response.AddHeader ("content-disposition",string. Format ("attachment; Filename={0}.xls", Httputility.urlencode (title +"_"+ DateTime.Now.ToString ("YYYY-MM-DD") , System.Text.Encoding.UTF8)); HttpContext.Current.Response.BinaryWrite (Ms.                    ToArray ());                HttpContext.Current.Response.End (); }            }        }
View Code

This method is good to find 1-side SQL can be downloaded, but excel in the Chinese column name, I think it will be in SQL as more trouble

2. Write HTML directly

① Find all the data you want

② use Linq.where () in all data to isolate the data to be used

③ then passes the model into the class, generating the HTML code

④ then write the website for download

About data filtering after Excel export download

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.