Solved

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

Posted on 1998-08-13
9
437 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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
 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

809 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