使用EPPLUS .CSV文件加载速度慢 [英] Slow loading of .CSV files using EPPLUS

查看:1934
本文介绍了使用EPPLUS .CSV文件加载速度慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要转换应用一些格式化后.xslx的.csv文件加载。

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

一个包含大约20 000行和列的7档需要12分钟转换。
如果文件中包含超过100个000它运行> 1小时。

A file containing approx 20 000 rows and 7 columns takes 12 minutes to convert. If the file contains more than 100 000 it runs for > 1 hour.

这是不幸的是没有适合我可以接受的。

This is unfortunately not acceptable for me.

代码段:

        var format = new ExcelTextFormat();
        format.Delimiter = ';';
        format.Encoding = new UTF7Encoding();
        format.Culture = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
        format.Culture.DateTimeFormat.ShortDatePattern = "dd.mm.yyyy";

        using (ExcelPackage package = new ExcelPackage(new FileInfo(file.Name))){
            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(Path.GetFileNameWithoutExtension(file.Name));
            worksheet.Cells["A1"].LoadFromText(new FileInfo(file.FullName), format);
        }



我已经验证它是花费占用了时间LoadFromText命令。

I have verified that it is the LoadFromText command that spends the time used.

有没有一种方法,以加快东西?
我已经尝试没有格式化的参数,但loadtime是一样的。

Is there a way to speed things up? I have tried without the "format" parameter, but the loadtime was the same.

什么loadtimes您遇到?

What loadtimes are you experiencing?

推荐答案

在这里我的建议是自己读取该文件,然后使用该库创建该文件。

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

读取CSV代码可以是简单的:

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

List<String> lines = new List<String>();
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
    }
}

这篇关于使用EPPLUS .CSV文件加载速度慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆