Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a Specified File in Excel from a GUI - Borland C++

I am using Borland Builder C++ 2009. I want to add a button to a form that allows the user to open a file in Excel that I specify. I can't think of how to do this. I know how to link with other code and executables -- is there a Microsoft Excel executable that I could use? How could I specify the file then? Any hints on this, or at least a place to look online, would be greatly appreciated.

like image 687
Shishiree Avatar asked Dec 22 '22 13:12

Shishiree


2 Answers

Assuming that the file type is registered with Excel, you could call ShellExecute() on the file, using the "open" verb. This will cause the file to be opened as if double clicked by the user in Explorer and will invoke Excel.

If that isn't the case, and you can assume that Excel is installed, you could instead pass "excel" to ShellExecute() as the application, and the path of the file as the parameter. (Note that I didn't test this, but it worked from the Run dialog, so I think that it should work from ShellExecute() as well).

like image 114
Andy Avatar answered Dec 30 '22 20:12

Andy


Thanks, Andy. I am using ShellExecute() as you suggested, giving Excel as the application and the path of the file as the parameter. It works to open Excel, however, it cannot seem to find the file. I have tried moving the file around, typing in the entire path, part of the path with no change. Here is the code I use:

ShellExecute(NULL, "open" ,"Excel.exe", "C:\\Documents and Settings\\Lab1\\My Documents\\Waypoint Tool.xls", NULL, SW_SHOWNORMAL);

So, I need to figure out why it isn't able to find this file.

Thank you for the suggestion to use ShellExecute though. I think I am on the right track!

like image 27
Shishiree Avatar answered Dec 30 '22 19:12

Shishiree