How to remove duplicate records from excel sheet using C#
How can I remove开发者_运维问答 the duplicate records from an excel sheet using C# and insert all the records except that duplicate one in another excel sheet?
If you mean that you want to read one sheet, filter the results, and then write out another sheet, I'd suggest you:
1) Read all the data from the sheet into memory (assuming its not excessively large).
2) Use LINQ or vanilla C# to filter the data, (I'd recommend LINQ's ".Where()" and ".Distinct()" operators myself).
3) Use the Excel API to write the data that remains into a new sheet.
If the spreadsheet(s) are very large, then you'll probably be best served by reading them into a database of some sort, and then relying on it for the filtration. You can use MS Access or SQLite as a small dedicated DB if you need.
Take a look at Create Excel (.XLS and .XLSX) file from C# 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.)
精彩评论