Epplus LoadFromText function load null Rows

Viewed 1392

I am using Epplus for uploading the data to database.When i am tring to convert my csv file to xlsx using LoadFromTest, extra null rows is also loaded into xlsx.I want to know,how we should restrict LoadFromText method not to Load Null empty Rows.

This is the code that helps to Convert CSV to XLSX format

 private void ConverCSVtoXlsx(ExcelPackage Package,string FileName)
        {
            var format = new ExcelTextFormat();
            format.Delimiter = ',';
            Package.Workbook.Worksheets["Believer List"].Cells["A1"].LoadFromText(new FileInfo(Server.MapPath(@"~\BelieverUploadFiles\" + FileName)), format, OfficeOpenXml.Table.TableStyles.Medium27, true);
            
            Package.Save();

        }

I have a screen shot in this link enter image description here

If see that image csv as only 2 rows with record and one heading Row.But after Converting 2 Record loaded with one Null row.Can anyone help on this

Thanks in advance

1 Answers

Probably best to process it manually before sending it to Epplus. You can do so with something like this:

var csv = string.Join(
    Environment.NewLine
    , File.ReadLines(csvfileinfo.FullName).Where(line => !string.IsNullOrWhiteSpace(line))
);

Package.Workbook.Worksheets["Believer List"].Cells["A1"].LoadFromText(csv, format, OfficeOpenXml.Table.TableStyles.Medium27, true);
Related