It looks like I may be learning any of the above for a work project. What we need to do is exchange data between our existing C++/MFC application and Excel spreadsheets or Access databases. I know there are ways to do this with OLE or COM but I’m having a hard time tracking down actual usable information. And of course, they’re all 3-letter acronyms, so I can’t use the board search.
So, questions:
[ul][li]What are the best methods for exchanging data as I’ve described? [/li][li]Where can I find good resources on learning OLE, ATL, COM, or whatever technology I might need?[/li][li]Do I even need OLE, etc.? Aren’t there existing MFC routines to handle the data exchange? We use MS Visual Studio 97, if that helps.[/li][/ul]
You can use an ODBC driver to connect to access. Create a DSN (data source name) with the ODBC administrator. You will probably want a system DSN. Use the DSN that is created in your connect string.
I don’t know C+ but VB would look like this -
set rstTest = Server.CreateObject(“ADODB.Recordset”)
rstTest.Open “SELECT * from " & SEARCHTABLE_NAME & _
" WHERE field = 2”, DSN=test
eniplas suggestion about using the ODBC driver might be a good way to go if your excel data is structured as a grid of data. The driver allows you to treat the excel file as if it were a database essentially.
The acronyms; OLE is the old name for COM. Initially the technology was seen as a way of embedding data from different applications into each other (hence the name Object Linking and Embedding). But it grew to be a means of creating high level objects. ATL, the Active Template Library (from when OLE was called ActiveX) is generally the most efficient way to develop applications that use COM. MSVC 6.0 offers a lot of builtin tools to make use of ATL, you can do the same stuff in MFC but it’s harder.
In terms of resources, I recommend the Wrox books, Beginning_ATL_COM_Programming and Professional_ATL_COM_Programming there is also one directed at working with Excel and other MS applications, but it’s name escapes me.
In terms of existing ways to do it, the old method was DDE, I have no idea if that is supported any more.
Just to nitpick, COM and OLE are two different things. COM is the communication protocol between applications (or libraries), and OLE is a framework on top of that protocol to allow embedding. For instance, I’ve used COM extensively, but know next to nothing about OLE.
At any rate, the easiest solution is to use VBA. If you are more comfortable in C++, VC++ 6.0 can do it for you. I haven’t used it, but probably the new .NET stuff can also do what you want.
As far as the ODBC and Excel, I’m not sure - my guess is probably they do not work together. You can do all sorts of things through VBA (and C++ using COM) by opening up the appication, however, and Microsoft provides a rich set of functions for controlling the Excel document.’
I think, (re sengles post) a grid of data is the way that you can get VB to look at excel.
You have some VB programmers trying to help you with C++ here so this is gonna be trouble
Anywho, look at - on your desktop > mycomputer > ODBC data sources. If you have office loaded (word, access, excel) you should have the ability to create a DSN, or data source name.
I have done some major battles with this stuff. Mostly trying to connect Informix. Great fun for all.