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?
- 1You're asking for sort of a lot. Can you show what you've written so far, and what you're having problems with? In the mean time, you might get some use out of this article on working with Excel with ADO.NET davidhayden.com/blog/dave/archive/2006/05/26/2973.aspxJuliet– Juliet2011-01-11 18:43:41 +00:00Commented Jan 11, 2011 at 18:43
- @Juliet: Please send me your mail ID..I will mail the code..Please help me I am struggling with this issue since 3 dayssaurav2109– saurav21092011-01-11 19:05:08 +00:00Commented Jan 11, 2011 at 19:05
- 2@saurav2109: Stackoverflow isn't a service where people mail each other code and get patched executables. Its also not a service where people write end-to-end applications for you. If you're having problems with your code, update your question with a small snippet of the code that's giving you a hard time, and people will help you out. (If you'd still like to rent me as a coder, that'll be $450/hr, 3 hr minimum ;) )Juliet– Juliet2011-01-11 19:21:55 +00:00Commented Jan 11, 2011 at 19:21
- Voting to close this question as clearly the OP is expecting a "scratch-my-back-and-I'll-scratch-yours" type of service.... nor even bothered to do a simplistic search... no real effort on the OP's part in how the problem was approached etc...t0mm13b– t0mm13b2011-01-11 19:27:44 +00:00Commented Jan 11, 2011 at 19:27
- Oh, and for what its worth, try to avoid using Excel as a database. Use a real database if possible.Juliet– Juliet2011-01-11 19:45:31 +00:00Commented Jan 11, 2011 at 19:45
2 Answers
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.
Comments
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.)