locked
Script to extract excel filenames and their row count RRS feed

  • Question

  • User496086301 posted

    I have like 500 excel files in a folder and I would like to output the filenames and their row count. Any efficient way?

    Sunday, September 30, 2018 2:46 PM

All replies

  • User-821857111 posted

    I would use EPPlus to load each file and get their row counts:

    var folder = @"C:\data"; // folder containing Excel files
    foreach(var file in System.IO.Directory.GetFiles(folder, "*.xlsx"))
    {
    	ExcelPackage package = new ExcelPackage(new FileInfo(file));
    	ExcelWorksheet workSheet = package.Workbook.Worksheets.First();
    	Console.WriteLine($"{Path.GetFileName(file)} has {workSheet.Dimension?.Rows.ToString() ?? "no"} rows");
    }

    https://www.nuget.org/packages/EPPlus/

    Monday, October 1, 2018 11:11 AM