Open specified file in Excel from GUI - Borland C ++

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

+4
source share
4 answers

Assuming the file type is registered in Excel, you can call ShellExecute () on the file using the "open" verb. This will cause the file to be opened as if it had double-clicked the user in Explorer and would call Excel.

If this is not the case, and you can assume that Excel is installed, you can instead pass "excel" to ShellExecute () as an application and the file path as a parameter. (Note that I did not test this, but it worked in the Run dialog, so I think it should work from ShellExecute () as well).

+4
source

Thanks Andy. I am using ShellExecute () as you suggested by providing Excel as an application and the file path as a parameter. It works to open Excel, however it cannot find the file. I tried moving the file by typing all the way, part of the path unchanged. Here is the code I'm using:

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

So, I need to find out why it cannot find this file.

Thanks for the suggestion to use ShellExecute. I think I'm on the right track!

+3
source

Try:

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

Looking at this page: http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx

It seems that he wants the file you want to execute to be included as the third parameter and the directory for the fourth.

+3
source

System() command should be sufficient, I think. For any Windows application, we can open any file using the location of the .exe file and the path to the file.

Eg.

 system("PATH C:\\Program\ Files\\Microsoft\ Office\\OFFICE11;%PATH% & excel \"C:\\Documents and Settings\\User\\Desktop\\ExcelFile.xls\""); 
+1
source

All Articles