Take a look at How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office? and choose an API to read from and write to the spreadsheet.
Many of them have SQL accessors, which will allow you to SELECT DISTINCT col1, col2, col3 FROM tableName. (You specify which columns you need to make the rows distinct.)