Dear all,

Is it ever possible to write a programme in C++ which enables me to:

1) Read the data in spreadsheet of MS-Excel

2) generate another Excel file as output ?

Also, are there any standard library could do the job?

One of my friend said using Visual Basic could make the task easier since it deals with Excel. Any comment on this?


Jim :rolleyes:

Your friend is dead wrong. Excel DOES include VBA which is a scripting language based loosely on VB but that's about it.

All of the MS Office applications expose a series of COM controls which you can use to manipulate their documents.
I don't have the documentation for them at hand but you should be able to find examples in the MSDN library at http://msdn.microsoft.com and elsewhere.

There are likely also other systems to access and manipulate the documents available through third parties.

There is a small code snippet on DaniWeb on how to manipulate Excel data from within qbasic. Your friend might not be so far off!

Another possability is to export the Excell code to XML, modify it, and pull it back into Excell. This works very well with Excell XP and later, not so well with versions earlier than Excell XP.

The "right" way to do it is with the COM calls, and the managed code (C#, VB) is generally easier to deal with COM than in C/C++. But using the XML method does not involve all that, nor does it require Excell to be present on the machine that does the conversion.

Thank you for all of your input.

Just to make the problem clearer:

In fact I have only learned C++ for one semester only but recently my professor asked me to write a programme like this. Since there's a time constraint and I only know C++, I have to choose from the 1 of the 2:

1) Use VC++, the language which I am more familiar with, but might be more difficult to implement GUI

2) Easier to make GUI but I know NOTHING about BASIC, not to mention VB.

I could also find some document from MSDN by searching for "automate Excel from Visual Basic" as mentioned by jwenting. But the code I found looks so hard and cryptic to me.

Anyway I have started learning VB today. Thank for all of your advice.

I have programmed a lot in VB and a little in C++. It will be easier in VB. The major obstacle you have in C++ is that there is an absense of documentation on the format - ie it is secret. There is a little bit of doco on the security features but that is all.

I have left an easier option underneath.

Try and think of VB as the C++ you learn in Kindergarten - Yes it is illogical, but it is still object oriented, it is just that you have to wade thru lots of new objects.

You have a few options
1) Use C++ to manipulate CSV files. You can save excel files as CSV files (comma separated). This would make it very easy with C++. Your instructor may consider this cheating as you are not technically manipulating an excel file, but ask. Maybe they want you to manipulate data as an exercise and don't care about the format. If so, this is the best way.
2) Use C++ to manipulate XLS files. As stated above, you must crack their format. No data exists on the web (except for very old formats of xl). Good Luck
3) Grit your teeth and learn VB.

I also want to do same thing,Read/write excel using C++.If u got solution can u sedn it to me.

Chetan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.