0

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?

8
  • 1
    You'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.aspx Commented 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 days Commented 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 ;) ) Commented 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... Commented 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. Commented Jan 11, 2011 at 19:45

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.)

1 Comment

Please take a look at sqlselect.org/cs-sql-select-distinct-access.html. Does that help?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.