epplus 速度,使用EPPLUS .CSV文件加载速度慢

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.

If the file contains more than 100 000 it runs for > 1 hour.

This is unfortunately not acceptable for me.

Code snippet:

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);

}

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

Is there a way to speed things up?

I have tried without the "format" parameter, but the loadtime was the same.

What loadtimes are you experiencing?

解决方案

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

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值