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?

Juliet
  • 80,494
  • 45
  • 196
  • 228
saurav2109
  • 21
  • 2
  • 4
  • 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 http://www.davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx – Juliet Jan 11 '11 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 – saurav2109 Jan 11 '11 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 Jan 11 '11 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 Jan 11 '11 at 19:27
  • Oh, and for what its worth, try to avoid using Excel as a database. Use a *real* database if possible. – Juliet Jan 11 '11 at 19:45
  • possible duplicate of [How to remove duplicate records from excel sheet using oledb](http://stackoverflow.com/questions/4660768/how-to-remove-duplicate-records-from-excel-sheet-using-oledb) – Michael Shimmins Jan 11 '11 at 20:39
  • @saurav2109: You've asked this question twice: http://stackoverflow.com/questions/4660768/how-to-remove-duplicate-records-from-excel-sheet-using-oledb – Michael Shimmins Jan 11 '11 at 20:40
  • This is a duplicate of [http://stackoverflow.com/questions/4660768/how-to-remove-duplicate-records-from-excel-sheet-using-oledb](http://stackoverflow.com/questions/4660768/how-to-remove-duplicate-records-from-excel-sheet-using-oledb) by the same user. – Jesse McCulloch Jan 11 '11 at 20:56

2 Answers2

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.

GWLlosa
  • 23,995
  • 17
  • 79
  • 116
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.)

Community
  • 1
  • 1
rajah9
  • 11,645
  • 5
  • 44
  • 57
  • Please take a look at http://www.sqlselect.org/cs-sql-select-distinct-access.html. Does that help? – rajah9 Jan 11 '11 at 19:55