Slow loading of .CSV files using EPPLUS

后端 未结 2 1088
后悔当初
后悔当初 2021-01-06 13:55

I have loads of .csv files I need to convert to .xslx after applying some formatting.

A file containing approx 20 000 rows and 7 columns takes 12 minutes to convert.

2条回答
  •  -上瘾入骨i
    2021-01-06 14:29

    My suggestion here is to read the file by yourself and then use the library to create the file.

    The code to read the CSV could be as simple as:

    List lines = new List();
    using (StreamReader reader = new StreamReader("file.csv"))
    {
        String line; 
        while((line = reader.ReadLine()) != null)
        {
            lines.add(line);
        }
    }
    
    //Now you got all lines of your CSV
    
    //Create your file with EPPLUS
    
    foreach(String line in lines)
    {
        var values = line.Split(';');
        foreach(String value in values)
        {
            //use EPPLUS library to fill your file
        }
    }
    

提交回复
热议问题