Epplus excel data export (when the data volume is a bit large) Web and Client, epplus data export

Source: Internet
Author: User

Epplus excel data export (when the data volume is a bit large) Web and Client, epplus data export

Asp.net MVC background code
Public ActionResult Export () {OfficeOpenXml. excelPackage ep = new OfficeOpenXml. excelPackage (); OfficeOpenXml. excelWorkbook wb = ep. workbook; OfficeOpenXml. excelWorksheet ws = wb. worksheets. add ("my worksheet"); // configuration file attributes // wb. properties. category = "Category"; // wb. properties. author = "Author"; // wb. properties. comments = "Remarks"; // wb. properties. company = "Company"; // wb. properties. keywords = "keyword"; // wb. properties. manager = "Manager"; // wb. properties. status = "content Status"; // wb. properties. subject = "topic"; // wb. properties. title = "Title"; // wb. properties. lastModifiedBy = "Last guaranteed"; // var list = GetList (); int x = 0; for (int I = 0; I <300000; I ++) {// if (x = 1000000) // {// ws = wb. worksheets. add ("my worksheet" + Guid. newGuid (). toString (); // x = 0; //} for (int j = 1; j <= 9; j ++) {ws. cells [(x + 1), j]. value = DateTime. now. toString () ;}x ++ ;}// write data // ws. cells [1, 1]. value = "Hello"; // ws. cells [1, 1]. style. numberformat. format = "yyyy-MM-dd"; // ws. column (1 ). width = 40; // modify the column Width // ws. cells ["B1"]. value = "World"; // ws. cells [3, 3, 3, 5]. merge = true; // ws. cells [3, 3]. value = "Cells [3, 3, 3, 5] merge"; // ws. cells ["A4: D5"]. merge = true; // ws. cells ["A4: D5"]. style. horizontalAlignment = OfficeOpenXml. style. excelHorizontalAlignment. center; // Center // ws. cells ["A4"]. value = "Cells [\" A4: D5 \ "] merge"; // write to the client (download) Response. clear (); Response. addHeader ("content-disposition", "attachment; filename=FileFlow.xlsx"); Response. contentType = "application/vnd. openxmlformats-officedocument.spreadsheetml.sheet "; byte [] data = ep. getAsByteArray (); Response. addHeader ("Content-Length", data. length. toString (); Response. binaryWrite (data); // ep. saveAs (Response. outputStream); Method 2: Response. flush (); Response. end (); return null ;}
FileInfo newFile = new FileInfo (@ "d: \ test.xlsx"); if (newFile. exists) {newFile. delete (); newFile = new FileInfo (@ "d: \ test.xlsx");} // using (ExcelPackage package = new ExcelPackage (newFile )) /// {// ExcelWorksheet worksheet = package. workbook. worksheets. add ("test"); // worksheet. cells [1, 1]. value = "name"; // worksheet. cells [1, 2]. value = "price"; // worksheet. cells [1, 3]. value = "sales volume"; // worksheet. cells [2, 1]. value = "rice"; // worksheet. cells [2, 2]. value = 56; // worksheet. cells [2, 3]. value = 100; // worksheet. cells [3, 1]. value = "Corn"; // worksheet. cells [3, 2]. value = 45; // worksheet. cells [3, 3]. value = 150; // worksheet. cells [4, 1]. value = "Xiaomi"; // worksheet. cells [4, 2]. value = 38; // worksheet. cells [4, 3]. value = 130; // worksheet. cells [5, 1]. value = "glutinous rice"; // worksheet. cells [5, 2]. value = 22; // worksheet. cells [5, 3]. value = 200; // package. save (); //} OfficeOpenXml. excelPackage ep = new OfficeOpenXml. excelPackage (newFile); OfficeOpenXml. excelWorkbook wb = ep. workbook; OfficeOpenXml. excelWorksheet ws = wb. worksheets. add ("my worksheet"); // configuration file attributes // wb. properties. category = "Category"; // wb. properties. author = "Author"; // wb. properties. comments = "Remarks"; // wb. properties. company = "Company"; // wb. properties. keywords = "keyword"; // wb. properties. manager = "Manager"; // wb. properties. status = "content Status"; // wb. properties. subject = "topic"; // wb. properties. title = "Title"; // wb. properties. lastModifiedBy = "Last guaranteed"; // var list = GetList (); int x = 0; for (int I = 0; I <100; I ++) {if (x = 1000000) {ws = wb. worksheets. add ("my worksheet" + Guid. newGuid (). toString (); x = 0 ;}for (int j = 1; j <= 2; j ++) {ws. cells [(x + 1), j]. value = DateTime. now. toString (); Console. writeLine (I + 1);} x ++;} ep. save ();

The Client Version can export at least 10 million data records. The Web version depends on the server memory configuration ..

Epplus download path: http://epplus.codeplex.com/

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.