Thursday, May 24, 2007

[C#] Loading and reading the Microsoft Excel file contents using C#

If you are not lazy, you can search the following CodeProject via Google within seconds: -
http://www.codeproject.com/useritems/Excel_Application_in_C_.asp
This mechanism can be used, but it has some considerations: for your deployment, you need to apply the Office component (which is using Microsoft.Office..blah blah blah..Excel, instead of the mentioned using Excel; ~!) to read the cells, that means, the deployment machine needs to purchase an extra Office licence for the deployment - most of the small businesses are reluctant to do so.. moreover, since this Office Object is version dependent, when the developer has an office version different from that in the client site, a nightmare .. XD
Therefore, you must ask: How can I accomplish that goal then?..
The answer is: SIMPLY USE StreamReader to directly read the file LINE BY LINE!..
If you don't trust me, you can try it yourself by setting similar Console App and you 'll get amazing results~!
This workaround is valid even for Visual Studio 2003, and the behind scene mechanism of that fussy StreamReader Object is a mystery to me..

No comments: