Reading from Excel File Visual C++ 2010 Express Edition
Hello all,
I am wanting to make a program that reads from an excel file and then writes that data to a csv file. I am aware I can do this through Excel and VBA, but this is not the best approach for my application. I need a simple console application that does this in the background without bringing up Excel and then I need to delete the file I made shortly afterwards.
I understand basics of C++, but every example I see is related to a actual windowed build with Visual C++ and nothing works for a console build. There are several tutorials that take Excel to HTML from C++, but I can't seem to get their code to compile, or have enough experience using any of their classes to modify them for my needs.
If someone could give me a simple snipet of code that will open up an excel file, read from a specific cell on a specific sheet and print that value to the screen, I would be forever grateful. After I get that information, I will be able to do the rest of what I am wanting to do.
Thanks in advance for any help!
Nathan
Re: Reading from Excel File Visual C++ 2010 Express Edition
You could use ADO to read data from excel sheet and then write them to text file.
Re: Reading from Excel File Visual C++ 2010 Express Edition
You can do it using ODBC and CRecordset also.
Re: Reading from Excel File Visual C++ 2010 Express Edition
Quote:
Originally Posted by
GCDEF
You can do it using ODBC and CRecordset also.
AFAIK VS 2010 Express does not contain MFC. :sick:
Re: Reading from Excel File Visual C++ 2010 Express Edition
ADO seems to have what I need. Any idea on what I am missing to include or namespace I should be using to resolve these erros?
Re: Reading from Excel File Visual C++ 2010 Express Edition
You have missed to define a pRec smartpointer (seems should be _RecordsetPtr, see in generated .thi). The same to TESTHR macro. It looks like you copied the snipped from somewhere, and the copy appears incomplete.
Re: Reading from Excel File Visual C++ 2010 Express Edition
Quote:
Originally Posted by
Igor Vartanov
You have missed to define a pRec smartpointer (seems should be _RecordsetPtr, see in generated .thi). The same to TESTHR macro. It looks like you copied the snipped from somewhere, and the copy appears incomplete.
Yeah, I noticed that after I downloaded the working source code and compiled. I've never gotten this detailed with C++ before (Assigning variant classes, include SQL DB stuff) and am trying to hack my way through it, but it is very cumbersome to figure out errors when you have no idea what they mean or enough of the language to know where to start looking.
After I get this thing actually working and know what each thing does, I will throw up my code because it seems to be a very needed topic and not that many step by step tutorials. Seems to be more of one decent C++ developer telling another C++ developer what Libraries to use. Nothing seems to capture the fact that maybe a developer not that familiar with the C++ language needs to do this task, but doesn't know enough about the language, yet, to get there.
Nathan
Re: Reading from Excel File Visual C++ 2010 Express Edition
In fact, you hit a very specific topic of importing COM server in your C++ program. Very little it has to do with C++ real complexities, but requires quite a good knowledge of COM technology.
I don't know the background, but say in VB, VBScript or JScript it would look much and much simpler, and maybe you should try with some language other than C++.
Re: Reading from Excel File Visual C++ 2010 Express Edition
I'm too close to turn back now ;) Only have to figure out how to select a certain 'Sheet' and everything else should work fine.
Re: Reading from Excel File Visual C++ 2010 Express Edition
Re: Reading from Excel File Visual C++ 2010 Express Edition
Re: Reading from Excel File Visual C++ 2010 Express Edition
Thanks for the replies Igor, very helpful.