Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1998-08-13
9
Medium Priority
?
475 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

636 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