EPPlusSoftware / EPPlus

EPPlus-Excel spreadsheets for .NET
https://epplussoftware.com
Other
1.8k stars 274 forks source link

Exporting more than MaxRows into CSV #755

Closed virzak closed 1 year ago

virzak commented 1 year ago

The library validates addresses in absolutely every situation

https://github.com/EPPlusSoftware/EPPlus/blob/6596f5135ac8cc455cd2baf7d9b555c7164d782c/src/EPPlus/ExcelRange.cs#L158-L167

However the 1,048,576 row limit only makes sense in excel context.

A test case below should be valid. It would be especially useful when more than 1,048,576 records need to be handled.

[TestMethod]
public void LongerThanMaxRows()
{
    var ws = _pck.Workbook.Worksheets.Add("LongerThanMaxRows");
    ws.Cells[1, ExcelPackage.MaxRows + 1].Value = "B";
    ws.Cells[$"A1:A{ExcelPackage.MaxRows + 1}"].SaveToText(new System.IO.FileInfo("myfile.csv"), new ExcelOutputTextFormat());
}

Would you consider a setting that would skip MaxRows and MaxColumns validation?

JanKallman commented 1 year ago

Why do you want this? Removing this limit will make the package corrupt, if you save it as xlsx or xlsm. It could also lead to other unexpected behaviours and performance issues.

virzak commented 1 year ago

if you save it as xlsx or xlsm

The purpose is to produce csv file. Why not validate when saving to xlsx/xslm instead? That way csv files can produce arbitrary number of rows and excel files will still be valid.

JanKallman commented 1 year ago

I don't think EPPlus is the right tool to create gigantic csv files. Removing the boundries of Excel can easily cause unexpected issues in EPPlus. Csv is just plain text, so you can easily write this using a normal FileStream . I assume you use functionality in EPPlus, as you want to use it, so I suggest you link worksheets if you have the need of 1M records +.