-
July 31st, 2013, 12:12 AM
#1
C++, C#, and Excel
Hi,
I just got a job programming a windows application. One of the requirements is reading and writing values from an excel spreadsheet. Looking online, it appears that C++ isn't the best (one of the worst?) languages for reading and writing values from excel files. Now the language I'm most familiar with is C++ and I've been looking at C#, and it appears to be much easier to read excel files. So I'm just debating what I should do, and I'm looking for advice. Do you think it might be easier to learn C#, since I'm quite familiar with C++, and write the application in C#? Or is using C++ with excel easier than it looks? Thank you very much for the help. This site has always been awesome.
Greg
-
July 31st, 2013, 01:28 AM
#2
Re: C++, C#, and Excel
![Quote](images/misc/quote_icon.png) Originally Posted by Gregorina
Hi,
I just got a job programming a windows application. One of the requirements is reading and writing values from an excel spreadsheet. Looking online, it appears that C++ isn't the best (one of the worst?) languages for reading and writing values from excel files. Now the language I'm most familiar with is C++ and I've been looking at C#, and it appears to be much easier to read excel files. So I'm just debating what I should do, and I'm looking for advice. Do you think it might be easier to learn C#, since I'm quite familiar with C++, and write the application in C#? Or is using C++ with excel easier than it looks? Thank you very much for the help. This site has always been awesome.
Greg
Hi. I don't know C#, but I know that you can work with excel very well from C++ ... you can find on the article section some good examples to how to work with excel from C++ ...
![Quote](images/misc/quote_icon.png) Originally Posted by Gregorina
Hi,
I just got a job programming a windows application. One of the requirements is reading and writing values from an excel spreadsheet. Looking online, it appears that C++ isn't the best (one of the worst?) languages for reading and writing values from excel files. Now the language I'm most familiar with is C++ and I've been looking at C#, and it appears to be much easier to read excel files. So I'm just debating what I should do, and I'm looking for advice. Do you think it might be easier to learn C#, since I'm quite familiar with C++, and write the application in C#? Or is using C++ with excel easier than it looks? Thank you very much for the help. This site has always been awesome.
Greg
Hi. I don't know C#, but I know that you can work with excel very well from C++ ... you can find on the article section some good examples to how to work with excel from C++ ... <url="http://www.codeguru.com/cpp/data/mfc_database/microsoftexcel/article.php/c11745/Microsoft-Excel-Automation-Class.htm">this</url> is the great one ... is the great one ...
Last edited by mesajflaviu; August 6th, 2013 at 01:41 AM.
-
July 31st, 2013, 07:11 AM
#3
Re: C++, C#, and Excel
Depending on how fancy you need to get, you can use ODBC and the CRecordset class to read and write to/from Excel. That's probably a bit easier than automation.
-
July 31st, 2013, 12:29 PM
#4
Re: C++, C#, and Excel
![Quote](images/misc/quote_icon.png) Originally Posted by GCDEF
Depending on how fancy you need to get, you can use ODBC and the CRecordset class to read and write to/from Excel. That's probably a bit easier than automation.
Ok, awesome, and thank you. Searching for ODBC and CRecordset, has given me some simpler examples than what I've seen before. Do you know of any tutorials for using ODBC and CRecordset? And of any code examples that can read both .xls and .xlsx?
-
July 31st, 2013, 12:36 PM
#5
Re: C++, C#, and Excel
![Quote](images/misc/quote_icon.png) Originally Posted by Gregorina
Ok, awesome, and thank you. Searching for ODBC and CRecordset, has given me some simpler examples than what I've seen before. Do you know of any tutorials for using ODBC and CRecordset? And of any code examples that can read both .xls and .xlsx?
Not off the top of my head. It's pretty easy though. Basic steps are use the ODBC administrator to create a DSN that points to an Excel spreadsheet. Use the IDE to create a CRecordset derived class that accesses that DSN. Uset the Open and MoveNext members to access the data.
-
July 31st, 2013, 02:52 PM
#6
Re: C++, C#, and Excel
![Quote](images/misc/quote_icon.png) Originally Posted by Gregorina
...One of the requirements is reading and writing values from an excel spreadsheet.
What do you mean by that? Reading the values? Or the formulas?
The big question is: is Excel present on the target system? It is way easier to automate Excel than to make sense of its file format manually.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
November 17th, 2013, 05:56 PM
#7
Re: C++, C#, and Excel
Here you may find an example how excel sheets can be read and written by C#
http://finaquant.com/table-function-...oft-excel/3788
This example shows, how c# methods can be called by excel macros (VBA), how excel sheets can be read and written by C#/.NET and how simple parameters (like string, integer and double) can be passed from excel VBA to C#/.NET.
In this example, the .NET-excel communication is accomplised through COM.
I hope it helps.
-
November 18th, 2013, 08:01 AM
#8
Re: C++, C#, and Excel
If you know C++ and don't know C#
then my advice would be "stick with what you know".
THe thing about C++ is that it doesn't come with built in support for COM as does C#, but it only takes something like the ATL or MFC COM wrappers to make dealing with COM a lot less of a hassle than it seems to be.
Alternatively write your own c++ wrapper around the Excel COM classes
THe thing to keep in mind is that languages like C# and VB don't really do all that much. The main "magic" in what they do is hiding all the HRESULT return values. VB handles this in OnError, C# has exceptions, oh look, C++ has exceptions too.
It's a recommended way to go for C++ also, "hide" the HRESULTS in exceptions. and then your COM interface code starts looking a lot more like regular C++.
-
November 18th, 2013, 09:56 AM
#9
Re: C++, C#, and Excel
This question was asked four months ago
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|