Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call excel from C++ ? 1

Status
Not open for further replies.

sheila11

Programmer
Dec 27, 2000
251
0
0
US
Hi all,

My C++ program saves its output data to a text file. (I am not using MFC or any of the windows files, but this program is running on Windows.) I have an Excel file that can read the data and display it in the form of a chart.

My problem is: how can I call the excel sheet to run from my C++ code?

Please help.

Thanks,
Sheila
 
Thank you so much! That was very useful.

The "ShellExecute" function requires absolute path to the folder in which my Excel file is. Is there a way to find the path to the current folder?

Thanks again,
Sheila
 
It should be a registry setting but I dont know which. There is also an alternative and that is automation. In that case you dont need the absolute path and you can directly interact with the app. The MSDN site has some info on this.

Matt
 
Did you meant "finding the path of the current folder" ?
If so,you can use this:

#include <stdlib.h>
#include<direct.h>
.....
char *Path = new char[_MAX_PATH];
_getcwd( Path, _MAX_PATH );
....
...
delete Path;


 
You can use another function called &quot;_spawnv&quot; to call and run an application.
 
Yes,there is a lot of them,there is also the simple &quot;WinExec&quot;

UINT WinExec(
LPCSTR lpCmdLine, // command line
UINT uCmdShow // window style
);

and the much more complex &quot;CreateProcess&quot;:

BOOL CreateProcess(
LPCTSTR lpApplicationName, // name of executable module
LPTSTR lpCommandLine, // command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
BOOL bInheritHandles, // handle inheritance option
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // new environment block
LPCTSTR lpCurrentDirectory, // current directory name
LPSTARTUPINFO lpStartupInfo, // startup information
LPPROCESS_INFORMATION lpProcessInformation // process information
);

but &quot;ShellExecute&quot; is a very good one.


 
There's also that according to the MSDN, 32-bit programs should not use WinExec.

;-)
 
pLEASE COULD YOU HELP ME! i'M NEW TO c++ I AM TRYING TO WRITE CODE WHICH THE OUTPUTS ARE VARIOUS NUMBERS BUT I WOULD LIKE TO PLOT THESE VALUES ON A GRAPH BUT AT THE MOMENT I HAVE TO WRITE EACH RESULT AND THEN PLOT THE GRAPH. IS IT POSSIBLE FOR THE OUTPUT TO BE SENT TO EXCEL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top