If this is in the wrong place, I apologize. I use ShellExecute only in Delphi, but I am aware that it may not be properly considered part of the language.

I have a program that is supposed to generate a .csv file for an output report. However, my boss wants this file to be printable, which would seem to imply opening the file in a spreadsheet; the simple .csv file wouldn't look very nice if printed out.

On my dev system, the .csv extension is associated with Notepad. Is there some way I can use ShellExecute (or any other call) to force the file to open in Microsoft Excel or OpenOffice Calc instead of opening in Notepad?

Recommended Answers

All 2 Replies

ShellExecute will always open the file with the associated program --in your case, with Notepad.

Take a look at CreateProcess instead. This will allow you to specify the program to run and pass as argument the name of the file to open.

I don't have the time at the moment, but if you are still struggling with it later I'll give you an example.

This isn't a solution with Delphi, but there is another way to make the extension .csv open with another application.

1. Right click the .csv file and click Properties.
2. In the General tab, you will see a button called Opens with...
3. All you have to do is click it and select Excel from the list of programs (or click Browse and navigate to Microsoft Excel if it does not show).

Although this is a non-Delphi method, it should solve your problem and you can use ShellExecute after you have set the default program to open a .csv file with Excel.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.