OpenXML performance is really poor it? NET Export Excel and evaluation of four methods

Bowen NET Export Excel and evaluation of four methods  in contrast to the four export performance libraries, but the evaluation of OpenXML is not high, I think it is reasonable, so I re-tested under performance

 

Based on the packaging ExcelDownWorker OpenXML

. 1  public  class ExcelDownWorker
 2  {
 . 3      void the NewRow (); // new line 
. 4  
. 5      void the Write ( Object value); // write column, the column A to start writing 
. 6  
. 7      void the Start (Stream Stream); // Create Start 
8 
9      void end (); // create end 
10 }

Data writing, the data is the front row of test data 10 6W

static void Excel(List<Temp> lt)
        {
            Console.WriteLine(GC.GetTotalMemory(true));
            var st = new Stopwatch();st.Start();var ew = new ExcelDownWorker();
            using (var fs = new FileStream(Directory.GetCurrentDirectory() + "\\data.xlsx", FileMode.Create, FileAccess.ReadWrite))
            {
                ew.Start(fs);
                var ps = typeof(Temp).GetProperties();
                foreach (var p in ps) { ew.Write(p.Name); }
                ew.NewRow();
                for (var i = 0; i < 1; i++)//用于测试12W,18W,102W
                {
                    foreach (var n in lt)
                    {
                        foreach (var p in ps) { ew.Write(p.GetValue(n)); }
                        ew.NewRow();
                    }
                }
                ew.End();
                fs.Flush();
            }
            st.Stop();
            Console.WriteLine(GC.GetTotalMemory(true));
            Console.WriteLine(st.ElapsedMilliseconds);
        }
class Temp
    {
        public int Id { get; set; }
        public int Gender { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public DateTime BirthDate { get; set; }
        public string Company { get; set; }
        public string Phone { get; set; }
        public string Website { get; set; }
        public string SSN { get; set; }
    }
static void Main(string[] args)
        {
            var s = File.ReadAllText(Directory.GetCurrentDirectory() + "\\test-data.json");
            var lt = DeserializeObject<List<Temp>>(s);
            for (var i = 0; i < 5; i++)
            {
                Console.WriteLine($"___________________第{i+1}次________________________");
                Excel(lt);
            }
            Console.ReadKey();
        }

Conclusion: OpenXML underwear, after all, have a good performance plasticity. 6W Processed 800 rows and 10 columns to 1000 milliseconds.

Guess you like

Origin www.cnblogs.com/xuzhiqiang/p/11420921.html