Solved

How to read/write Excel file from VC++...

Posted on 1998-08-13
9
428 Views
Last Modified: 2012-06-27
I want to read/write Excel file from my VC++(v5.0) project.
I try to use OCX to do it, but the speed is too slow
(e.g: take 15 seconds to read 1000 cell, by the way
the OCX is writed by using VB).
My question is: are there other methods to do this job
and get better performance and how to do it ?
0
Comment
Question by:nature1
9 Comments
 

Author Comment

by:nature1
ID: 1170235
Edited text of question
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1170236
Perhaps you write a macro in VBA which exports the table into a file and then you fetch
that file ... I don't think that there is another way than the way you tried.
Good luck :)
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1170237
If you just want to write out a data file that Excel can read, then write out a CSV file.  Excel can export this, and you can write this very fast from a C program (e.g. using the file APIs).

If you to write a true Excel file (e.g. you want formatting and macros etc. in the spreadsheet) get the Excel SDK which is kind of a book and disk (there's a reference to it on Microsoft Developer's Network).  Even an old SDK will work as new Excels read old formats.  

The other alternatives are to use the Formula 1 Spreadsheet control (OCX) which I believe can write Excel files, or use the OLE Structured format of that the new versions of Excel use (this is also documented on MSDN, but I can't find the article at the moment - I've seen it before)
0
 

Author Comment

by:nature1
ID: 1170238
Thanks for your answer.

Perhaps my question is not clear.
What I want to do is: get/put cell value
from/into a real excel file(.xls) very fast
from a VC++ program.

What I have done is:
1) Use VB to wrote a ActiveX control which use
   following lines to get/set cell value in its methods:
   ...
   GetCellData = xlsheet.Cells(i,j).Value
   ...
   xlsheet.Cells(i,j).Value = value_to_set
   ...
2) Use IDispatch wrapper class to wrap this ActiveX Control
   in my VC++ project.

This approach can work, but performacne is not good.
By the way, my PC is Pentium_90MHz/96M memory.

Thanks again for your respones.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 6

Expert Comment

by:snoegler
ID: 1170239
The only ways i see are:
a) like answer2000 proposed, to purchase a SDK to access excels data files directly
b) write the ActiveX control wrapper with Visual C++ directly
    ( i think this should work with 'Insert|Component...|Ole Controls ...')
    Even if this works, i think the performance gain will be if any really small.
c) To contact microsoft directly and ask them for support - sometimes they can be really help-
     ful. Perhaps you can get a documentation on the file format with complete specifications
     (specific for Excel) - or even a doc of the dll's which are used by excel itself.
d) Perhaps you can get an ODBC driver to access the excel sheets
 
0
 

Expert Comment

by:nancytan
ID: 1170240
I have done searching and reading of string and number in Excel file with P200, 128MB and with speed is quite slow too.
The other difference is i use a dll instead.

Is ocx faster than dll?
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1170241
What dll are you talking of? I think it is possible to access the whole Excel application itself
as an 'OLE control' - I am not sure though. This way *could* be quite fast, but i don't know,
i've never tried it (as i don't have excel).
Could you explain any further what you mean with
  >> Use VB to wrote a ActiveX control which use ...
Do you mean VBA or did you write an OCX wrapper class using VB?

0
 
LVL 6

Accepted Solution

by:
snoegler earned 200 total points
ID: 1170242
There is an ODBC excel sheet driver provided with the MSVC distribution, i realised.
Choose your MSDev setup, and install the ODBC excel driver. So you can access your
'.xls' files using ODBC - which isn't too fast, but i think it should be MUCH faster than
15sec for 1000 cells.
0
 

Author Comment

by:nature1
ID: 1170243
Thanks for your answer.
By the way I wrote that OCX by creating a "ActiveX Control"
project and using "Make ...ocx" menu item of File.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on thā€¦
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a Gā€¦
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now