execute csv created files

Other discussions about CSPro
AriSilva
Posts: 162
Joined: July 22nd, 2016, 3:55 pm

execute csv created files

Postby AriSilva » April 9th, 2018, 3:13 pm

Is there a function in cspro that returns the excel.exe complete path?
I´m creating some csv files and I want to call execsystem passing the filenames as parameters to be executed by excel. Something like

acc = execsystem( maketext("C:\Program Files\Microsoft Office\Office15\excel.exe %s ", filename) );

This works pretty well on my machine, but I have to install the application in someone else´s computer.
Best
Ari

AriSilva
Posts: 162
Joined: July 22nd, 2016, 3:55 pm

Re: execute csv created files

Postby AriSilva » April 11th, 2018, 10:56 am

There is a function in windows named WinExec that supposedly does the job in finding where excel is and execute it.

https://msdn.microsoft.com/en-us/librar ... 93(v=vs.85).aspx

which can be executed in C++ (I did not try it), but I was unable to call it inside the execsystem function.
Ari
Best
Ari

aaronw
Posts: 77
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: execute csv created files

Postby aaronw » April 11th, 2018, 11:28 am

How about a CSPro function that checks default installation paths for Excel? You'll need to add additional installation paths to the versions array.
PROC GLOBAL

numeric total_versions = 2;
array string versions(total_versions) = "Microsoft Office\Root\Office16\EXCEL.EXE", "Microsoft Office\Root\Office13\EXCEL.EXE";

function string GetExcelPath()

    GetExcelPath = "";

    do numeric i = 1 while i <= total_versions

        string testPath = maketext("%s%s", pathname(ProgramFiles64), versions(total_versions));
        if fileexist(testPath) then
            // 64-bit
            GetExcelPath = testPath;
            exit;
        endif;

        testPath = maketext("%s%s", pathname(ProgramFiles32), versions(i));
        if fileexist(testPath) then
            // 32-bit
            GetExcelPath = testPath;
            exit;
        endif;

    enddo;

end;

josh
Posts: 1609
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: execute csv created files

Postby josh » April 11th, 2018, 11:29 am

There are a couple of tricks you can use to do this:

If the file associations on your system are setup so that csv files are opened in Excel then you launch explorer.exe to open the csv file. Usually when you install Excel it creates this association so unless your user has changed this setting this trick should work. Instead of trying to run Excel directly, the trick is to launch Windows explorer (explorer.exe) and pass it the csv file. This will automatically launch the CSV file with whatever program is associated with the file extension .csv.

execsystem(maketext('explorer.exe "%s"', pathname(Application) + "test.csv"));


The second trick is to use a DOS bat file to launch Excel. In a bat file you can use the start command which can launch Excel without specifying the full path. You can use filewrite to write out the .bat file and then use execsystem to run it:

setfile(launchScript, pathname(Application) + "launchcsv.bat");
filewrite(launchScript, "");
filewrite(launchScript, 'start Excel.exe "%s"', pathname(Application) + "test.csv");
close(launchScript);
execsystem("launchcsv.bat");

AriSilva
Posts: 162
Joined: July 22nd, 2016, 3:55 pm

Re: execute csv created files

Postby AriSilva » April 12th, 2018, 9:07 pm

Thanks aaronw and Josh for your suggestions.
The problem with aaronw´s is that the combinations are difficult to preview, like in my computer the excel.exe is in
C:\Program Files\Microsoft Office\Office15\excel.exe.
Since in most environments, when you install excel it connects the csv extension, I´ll put my chips in the explorer.exe (Josh´s first suggestion). I already tried it, and it works.
As for the DOS solution, it is good thinking also, and it should work.
Thanks again for your very helpful comments.
Best
Ari
Best
Ari


Return to “Other”