Solved

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

Posted on 1998-08-13
9
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

733 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