简体   繁体   中英

How to Export Bulk data into Excel in C# (WPF) using Epplus?

Getting Memory out Exception during Export the bulk data having above 300000 rows

using (var p = new ExcelPackage())
 {

            ExcelWorksheet ws = CreateSheet(p, _workbookProperties.WorksheetName);



            ws.Cells[1, 1, 1, dt.Columns.Count].Style.Font.Bold = true;
            ws.Cells[1, 1, 1, dt.Columns.Count].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

            int rowIndex = 1;

            CreateHeader(ws, ref rowIndex, dt);
            CreateData(ws, ref rowIndex, dt);
            //CreateFooter(ws, ref rowIndex, dt);




            Byte[] bin = p.GetAsByteArray();

            var tempFolder = Environment.ExpandEnvironmentVariables("%TEMP%");
            string file = String.Format("{0}\\{1}-{2}.xlsx", tempFolder, _workbookProperties.WorkbookName, DateTime.Now.ToString("MMddyyyymmss"));
            File.WriteAllBytes(file, bin);


            //These lines will open it in Excel
            var pi = new ProcessStartInfo(file);
            Process.Start(pi);
        }

将应用程序更改为64位,您将解决内存问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM