how to read data from .xls files?

Pages: 12
Hi EverBeginner!

Do you mean to the PowerBASIC program? I'm assuming you do because I have everything needed for the C++ program posted above. PowerBASIC was created by Bob Zale who is one of the premier compiler writers around. He worked with Borland back in their heyday and TurboBasic was his product. After DOS faded away he left Borland and started publishing Win32 Basic compilers, and named his company PowerBASIC. Their stuff is dynamite and few people know of it due to Microsoft's dominance in the development tools business. I use it exclusively for my desktop Windows work and I use C++ for my Windows CE work because PowerBASIC only produces Windows compilers - not Windows CE or Linux. Here's a link...

http://www.powerbasic.com

The above program that reads the Excel data comes in around 39K, which isn't too bad when you figure powerful string handling routines are build right into the language, as well as high level support for COM and OOP. If you want you can write low level COM too, but most folks hate that. I've a number of low level COM tutorials posted here...

http://www.jose.it-berater.org/smfforum/index.php?board=362.0

using both C/C++ and PowerBASIC and at that site are a lot of advanced coders and programming info.

After .NET hit back around 2002 a certain percentage of coders migrated to PowerBASIC because it was a high performance compiled language with a lot of low level capabilities. I'd highly recommend it. The fellow who runs the MASM32 forum - Steve Hutcheson - Hutch...

http://www.movsd.com/masm.htm

is a big PowerBASIC supporter and has a board too at my above link.

That include file listed at the top of the PowerBASIC program...

PBExcel.inc

That is auto generated by the PowerBASIC Ide. That is actually a rather large file because Excel has so many COM methods associated with it. The way it is made is from a menu in the IDE it brings up a Type Library Browser that lists all the installed COM components on a system. You would scroll through them until you found something like 'Microsoft Excel Object Library' or something like that; then you would double click on it and the ide would read the type library and auto-generate that data. You would then save it to any file name you wanted and include it, then the compiler would have all the interface definitions so it could do early binding on the IDispatch interface. Its also possible to not use that file and do late binding, but there is a performance hit with that as two trips to the server are needed. Basically, the IDispatch thing is miserable but with some COM objects that is the only way to connect. I have it on good authority that direct VTable access with Excel doesn't work.
Last edited on

C++ is a wonderful and powerful language, but its just not the best choice for some things, and this is one of them.


I agree M$ Excel is one of the most used applications and despite M$ not releasing the official .xls binary file format, a lot of Open Source project has deciphered it (almost 99% I would say). They reverse engineer it. They inspect the bytes inside the .xls to come out with the format. Once the format is deciphered, it is a matter of time a library is created with methods to do what user wants.

Apache POI http://poi.apache.org/ is one effort going on. They also decipher M$ Word format too and they release a Java library for Java developers to use when they want Java program to read/write data to M$ office documents.

I believe if there is a similar Open Source project in C++ can do that too. Instead they can approach the above Java team for the deciphered binary file format and then build their own C++ libraries that allow C++ program to read/write data to M$ office documents too. Unfortunately C++ developers do not have so much help as compared to their Java counterparts :P

I always feel Java has much more "business-centric" API to offer in comparison to C++ counterparts :)
... and despite M$ not releasing the official .xls binary file format, ...
I never thought I'd ever catch myself defending Microsoft's policies, but I have to say you're wrong on this one. Microsoft did release the Excel file format with version 4. It's a series of BIFF (binary interchangeable file format, I think) records.

Post Excel 4, the decision was to export Excel functionality through the COM interface in the new age of OO. And code has been posted in this thread that uses that interface to access the spreadsheet using this technology.

Although many products claim to real Office files, what they cannot preserve is the relationship with objects. For example if your spreadsheet/doc has an embedded or linked object (using OLE), that relationship cannot be preserved by just readin files. You need an proper object model that's most sensibly provided by an object interface, not a file interface.
Although many products claim to real Office files, what they cannot preserve is the relationship with objects. For example if your spreadsheet/doc has an embedded or linked object (using OLE), that relationship cannot be preserved by just readin files. You need an proper object model that's most sensibly provided by an object interface, not a file interface.


Agree. But for simple needs like read/write data with not much complicated stuff, Apache POI serve Java developers immensely. If only C++ has something equivalent and make C++ developer life easier without needing to wade through all those COM details!

Not to mention PDF has been done using Apache PDFBox or iText. Again it is for Java. Hope to see a library for C++ though :P

The day where C++ can release more "business-centric" API or library is the day C++ can challenge Java seriously in the business application logic arena. Currently C++ is still very much relegated to the back-end servers doing high performance processing jobs (Except M$ products though :)
True. The real power of Java is in the set of available libraries. C++ has nothing like that and is rather parochial in this regard.
And I bet Peripheral thought he was asking a simple question!
Really though, isn't there something in MFC to wrap the low level COM Apis so they don't have to be used directly? I don't do MFC, so I don't know. That's why I'm asking.
No. ATL wraps COM. But even that VB sample was a pain. The ATL version is similar.
Last edited on
yes,I thought it was easy, just as to read txt file.

now compiled in vc 6.0

in the main.cpp fatal error C1083: Cannot open include file: 'Strings.h': No such file or directory
Error executing cl.exe.

in fact the Strings.h is already exist in the project.

what is wrong?
Last edited on
freddie1 posted that code earlier in the thread.
Topic archived. No new replies allowed.
Pages: 12