Solved

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

Posted on 1998-08-13
9
431 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

864 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

25 Experts available now in Live!

Get 1:1 Help Now