Excel and OLE DB
-
Hello. I am working on a project which involves reading from and writing to an excel file. I'm having a few bugs at the moment. I can only get it to write if there is already data saved in the excel file. Second, after it does save the data, my attempt to re-read it only results in OLE stating that there is only one column of data, even though there is obviously 3. It works if i resave it in Excel, but that's not really a viable option as this program is supposed to automate things. If anyone has experience with OLE and has a solution or at least a suggestion for some of these problems, please post a response. Thanks in advance.
-- Steven Hunt
-
Hello. I am working on a project which involves reading from and writing to an excel file. I'm having a few bugs at the moment. I can only get it to write if there is already data saved in the excel file. Second, after it does save the data, my attempt to re-read it only results in OLE stating that there is only one column of data, even though there is obviously 3. It works if i resave it in Excel, but that's not really a viable option as this program is supposed to automate things. If anyone has experience with OLE and has a solution or at least a suggestion for some of these problems, please post a response. Thanks in advance.
-- Steven Hunt
Yes I've done this and you want to look on codeproduct for a free class that allows writing/reading of excel files.
Blog Have I http:\\www.frankkerrigan.com
-
Hello. I am working on a project which involves reading from and writing to an excel file. I'm having a few bugs at the moment. I can only get it to write if there is already data saved in the excel file. Second, after it does save the data, my attempt to re-read it only results in OLE stating that there is only one column of data, even though there is obviously 3. It works if i resave it in Excel, but that's not really a viable option as this program is supposed to automate things. If anyone has experience with OLE and has a solution or at least a suggestion for some of these problems, please post a response. Thanks in advance.
-- Steven Hunt
You can use ADO.net (or just plain ADO) and treat the excel sheet like a datbase table. Use the Jet Engine with an excel specific connection string and reference the appropriate sheet as $SheetName (sheet name prefixed with $). I have used Carlos Antonini's C++ ADO wrapper classes successfully with Excel in this way. ADO.Net with DataTables/DataReaders and SQL commands works as well.