Asp.net excel export function, asp. netexcel

Source: Internet
Author: User

Asp.net excel export function, asp. netexcel
The following are my Excel export functions in project development. I hope you can correct them and learn from each other.

Protected void btn_Export_Click (object sender, EventArgs e) {string FileID = ""; if (Request. QueryString ["fujiian"]! = Null & Request. QueryString ["fujitsu"]. ToString ()! = "") {FileID = Request. queryString ["fujiian"]. toString () ;}string title = GetFileTile (FileID); // file title Workbook workbook = new Workbook (); // workbook Worksheet sheet = Workbook. worksheets [0]; // worksheet Cells = sheet. cells; // cell // column width cells. setColumnWidth (0, 20.00); cells. setColumnWidth (1, 30.00); cells. setColumnWidth (2, 30.00); cells. merge (0, 0, 1, 3); // Merge cells [0, 0]. putValue (title + "/List of persons who have learned Files"); cells [0, 1]. putValue (""); cells [0, 2]. putValue (""); cells [1, 0]. putValue ("Serial Number"); cells [1, 1]. putValue ("name"); cells [1, 2]. putValue ("time"); string SQL = "order by StudyTime"; ds = PublishBLL. getCommentCount (FileID, SQL); if (ds. tables [0]. rows. count> 0) {for (int I = 1; I <ds. tables [0]. rows. count + 1; I ++) {// Aspose. cells. style styleTitle = workbook. styles [workbook. styles. add ()]; // Add a style // styleTitle. horizontalAlignment = TextAlignmentType. center; // text Center // styleTitle. font. name = ""; // text font // styleTitle. font. size = 18; // text Size // styleTitle. font. isBold = true; // bold cells [I + 1, 0]. putValue ("" + I. toString (). padLeft (3, '0') + ""); cells [I + 1, 1]. putValue ("" + ds. tables [0]. rows [I-1] ["StudyName"]. toString () + ""); cells [I + 1, 2]. putValue ("" + ds. tables [0]. rows [I-1] ["StudyTime"]. toString () + "") ;}} string filename = "Statistics" + DateTime. now. toString ("yyyyMMddHHmmss") + ". xls "; string path = ConfigurationManager. deleetask[ "StudyFile"] + @ "\" + filename + ""; workbook. save (path); // Save it to the hard disk # region Download System. IO. memoryStream ms1 = workbook. saveToStream (); // generate data stream byte [] bt1 = ms1.ToArray (); string fileName = "Statistics" + DateTime. now. toString ("yyyyMMddHHmmss") + ". xls "; // file name saved by the client // download the file Response in the form of a Response stream. contentType = "application/vnd. ms-excel "; // notify the browser to download the file instead of opening Response. addHeader ("Content-Disposition", "attachment; filename =" + HttpUtility. urlEncode (fileName, System. text. encoding. UTF8); Response. binaryWrite (bt1); Response. flush (); Response. end (); # endregion}

  

Related Article

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.