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/