0

I have to compare two Excel files having different number of sheets, different number of columns/rows, merged cells, formulas etc.

The output of the comparison should allow the user to see which rows/columns were added, deleted, modified, re-arranged. This whole thing has to be done using C#,.NET

Can anyone help me out?

Kara
  • 6,115
  • 16
  • 50
  • 57
Sandepku
  • 861
  • 14
  • 31

3 Answers3

2

You need to define your scope better. As @Brijeesh suggested, there are 3rd party libraries like EPPLus, and also NPOI for reading the files. But this is not about reading the files, but rather performing some "comparison" that you have an idea in your head how you want it to happen.

This question is too broad to be answered in a single thread like this.

  • Are the spreadsheets in a known format?
  • Do you only want to check certain sheets / columns ?
  • You mentioned wanting to see which columns were re-arranged, this implies knowing what order they were in the first place. Again - is the spreadsheet in a known format?

You should start to answer these questions, and trim down the scope of what you're trying to do into manageable tasks.

EDIT:

VSTO has its benefits, and it's downfalls (the user must have excel installed). 3rd party libraries also have their ups and downs. Which method you should use for accessing the spreadsheets was not the question in this thread.

Again - focus on one thing at a time. What do you want to compare, and how do you want to do it? Then you can worry about which library you should use. Though - when you're ready to ask that question, open a separate question so that the posts can stay on topic.

Origin
  • 1,943
  • 13
  • 33
  • Thanks Origin, but honestly speaking, the scope has not been defined at all, I need to implement anything and everything, like, new rows can be added, new columns can be added, rows can be re-arranged , columns can be re-arranged, row data can be merged, column data can be merged, new sheets can be added and what not. I am sorry.. but yes, I have half baked requirements and believe me I am in soup. The format of the excel sheet has not been fixed. – Sandepku Jan 03 '12 at 04:43
  • 1
    Then you may as well have asked how you could write Microsoft Excel from scratch. As @AMissico already stated, you could use the Tracking feature of Excel if you really need this level of tracking. Don't re-invent the wheel. – Origin Jan 03 '12 at 04:45
  • Thanks Origin, but can the tracked change be read into an app using an C# API – Sandepku Jan 03 '12 at 04:47
  • I don't know - you'll have to read the Office Interop docs. What do you intend to do with the changes once you have them? – Origin Jan 03 '12 at 04:54
  • I need to show them to the end user. he will take some action based on them – Sandepku Jan 03 '12 at 04:57
  • 1
    Again - why can't this just be done with the existing revision control in Excel? If your goal is to make it so they don't need to have Excel installed, you won't be able to use the Office Interop for this anyway. And - implementing the same features with a library like NPOI or EPPlus is not a one-person job. – Origin Jan 03 '12 at 05:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/6330/discussion-between-sandepku-and-origin) – Sandepku Jan 03 '12 at 05:08
0

have a looka at epplus if that doesnt fits your requirement use VSTO/office interop

Brijesh Mishra
  • 2,738
  • 1
  • 21
  • 36
  • Hi Brijesh, should I go for a cell by cell comparison in that case, if I use office interop.. its kind of too much cases to cover;; to code by hand.. pls correct me if I am wrong. – Sandepku Jan 03 '12 at 04:36
0

I created a spreadsheet macro that compares two spreadsheets together and highlights differences. You have to login to download it but you can use your Google login. The VBA code is not locked and it might give you a start to port it to C#

http://www.run8tech.com/tools.aspx

Nate
  • 1
  • 1