Search code examples
c#asp.net.netxlsx

read an xslx file and convert to List


I have a xslx file with following data

    www.url.com
    www.url.com
    www.url.com
    www.url.com
    www.url.com
    www.url.com
    www.url.com
    www.url.com
    ...

Like you can see I have only 1 column used and a lot of rows. I need to read that column from the xslx file somehow and convert it to List<string>.

Any help?

Thanks!


Solution

  • You can use EPPlus, it's simple, something like this :

      var ep = new ExcelPackage(new FileInfo(excelFile));
      var ws = ep.Workbook.Worksheets["Sheet1"];
    
      var domains = new List<string>();
      for (int rw = 1; rw <= ws.Dimension.End.Row; rw++)
      {
        if (ws.Cells[rw, 1].Value != null)
         domains.Add(ws.Cells[rw, 1].Value.ToString());
      }