c# NPOI 导出23万条记录耗时12秒

string connectionString = "Server=localhost;Initial Catalog=******;User ID=sa;Password=******;"; List<TestData> datas = null; using (SqlConnection db = new SqlConnection(connectionString)) { datas = db.Query<TestData>("SELECT * FROM TestData").ToList(); } System.Console.WriteLine($"数据源对象 {typeof(TestData).GetProperties().Length} 个字段,共 {datas.Count} 条记录,大小 {BinarySerializeHelper.SerializeToBytes(datas).Length/1000/1000} M"); Task.Run(() => { while (true) { System.Console.WriteLine($"{DateTime.Now} 内存 : {GC.GetTotalMemory(false) / 1000 / 1000} M"); Thread.Sleep(1000); } }); Stopwatch sw = new Stopwatch(); sw.Start(); byte[] bytes = ExcelHandlerFactory.CreateHandler(datas).CreateExcelBytes(); sw.Stop(); System.Console.WriteLine($"{DateTime.Now} 数据源转Excel文件字节数组耗时 : "+sw.ElapsedMilliseconds / 1000 +""); string path = @"C:\Users\Administrator\Desktop\1.xlsx"; FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(bytes); fs.Dispose(); System.Console.ReadKey();

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpzfys.html