Execute Excel File w/Fortran Compiler Code

  • Fortran
  • Thread starter ethyl
  • Start date
  • Tags
    Fortran
In summary, you cannot execute an Excel file directly through a Fortran compiler, but you can use a batch file or ShellExecute() function in C/C++ to run the Excel file after your program finishes. To export data to an Excel file from a Fortran program, you can output a text file with appropriate formatting and open it with Excel. Additionally, you can use a variable to dynamically name the file you want to open in your Fortran code.
  • #1
ethyl
7
0
Is there any code that i can use to execute a file through a fortran compiler? For example i want to execute an excel file (kk.xls) just before the termination of the main code.
Thank you
 
Technology news on Phys.org
  • #2
You can't "execute" an Excel file. You might want to be more specific about what you mean.

- Warren
 
  • #3
I want to write a code line that will call an excel file after running the main code. I just want to call the file! Not input or export any data. So just before the code terminates it will call this file on the screen. just that. although i don't know if it is possible.
 
  • #4
Sounds like you want to run Excel with a file you created from your program. This could be done via a batch file that first runs your program and then runs Excel. If you want to run Excel from within your program via an internal command line interface, your Fortran compiler would have to support this. It would be nice if the Excell program could be launched as an independent task so your program could exit and not occupy space after it's done and the Excell program starts.
 
  • #5
Exactly Jeff! But how am i doing that?
 
  • #6
What you want is the equivalent of ShellExecute() that is available in Microsoft C or C++ compilers. The alternative is to create a dos console batch file and then optionally create a shortcut to the batch file in a program folder.

To create shortcuts:

Click on start, right click on all programs. Create a new folder. Double click on the new folder to open it. Right click on folder window and select new, shortcut. Search for your program (the .exe) file. If the program has an icon in it, it will automatically get picked up. If there are parameters, add them after the name of the program when creating the shortcut. Click on next and change the name if you want.

If you didn't get an icon for the shortcut, right click on the shortcut, and click on change icon, and again, fine the .ico file for your program. Windows will start off with the generic set of icons from some .DLL file. You can pick up icons from .DLL files, .EXE files, or .ICO files.

Note that this same process can also be used to create shortcuts to .BAT file to run command scripts. For Windows XP or Vista batch files, prefxing a program path and name with start, such as

start \myfolder\myprogram1.exe
start \myfolder\myprogram2.exe

allows multiple programs or multiple instances of a program to be launched with a single shortcut to a batch file.
 
  • #7
buy saing program you mean the file that contains the fortran code or the excel file? Because non of them is a .exe file. And then still what is the code to call the file from the fortran compiler? I want to call my excel file from the fortran code not make a script that will call both the fortran compiler to open and the excel file as well.
 
Last edited:
  • #8
ethyl said:
ShellExecute()
You mean the file that contains the fortran code or the excel file?
I don't know about the Fortran compiler. Using the ShellExecute() function in C / C++, you could choose to "open" or "edit" the file, which would autolaunch Excel if the file had an "Excel" associated suffix, such as SAMPLE.XLS. You could also to choose to "open" Excel.EXE with your created SAMPLE.XLS file as a parameter.
 
  • #9
1) Is there any code that can make a fortran compiler to export data to an excel file?
But not just OPEN(3,FILE='Z2.xls') for example because it is inserting the data in a messed up way and i can not draw a graph.

2)Also another in fortran code let's say we ve got OPEN(2,FILE='kk1.DAT') The part of the code in
' ' is understood by fortran as the name of the file that will open. Can i make 1 to be a variable so if i create a loop the name of the file will take the value of the variable. For example OPEN(2,FILE='kkX.DAT') where X will be the variable.
 
Last edited:
  • #10
ethyl said:
1) Is there any code that can make a fortran compiler to export data to an excel file?
Output a text file SAMPLE.TXT, then open this with Excel.
Use spaces, or commas to separate the numbers on each line of the text file.
 
  • #11
1) Is there any code that can make a fortran compiler to export data to an excel file?
But not just OPEN(3,FILE='Z2.xls') for example because it is inserting the data in a messed up way and i can not draw a graph.

Create/open a file as a text file, not .xls. Then when you write the data cells, insert tabs between each cell when you want to create new columns, or insert crlf if you want to make a new row. Then run the text file but open using using Excel. Specify tab separation between the cells.

2)Also another in fortran code let's say we ve got OPEN(2,FILE='kk1.DAT') The part of the code in
' ' is understood by fortran as the name of the file that will open. Can i make 1 to be a variable so if i create a loop the name of the file will take the value of the variable. For example OPEN(2,FILE='kkX.DAT') where X will be the variable.

Yes you can do this. You will have to create the file name as a string variable by concatenating various components. First convert the number variable to an ascii character string, then concatenate 'kk' + 'numberVariable + '.DAT' and call it something else. Then OPEN(2,FILE='somethingElse')

BTW I do not know any Fortran compilers that will directly call up an run an .exe program such as with ShellExecute() in C++. If you do this in C you will likely have to call "Excel.exe mySpreadsheet.xls". You may also have to call the Excel .exe and or the spreadsheet name as a full file pathname, e.g. "C:\blah\blah\mySpreadsheet.xls"
 
  • #12
ChrisLeslie said:
Yes you can do this. You will have to create the file name as a string variable by concatenating various components. First convert the number variable to an ascii character string, then concatenate 'kk' + 'numberVariable + '.DAT' and call it something else. Then OPEN(2,FILE='somethingElse')

Thank you for your answer. I do not know how to create a string variable or an ascii character or how to concaternate the variables together :S Can you be a little more detailed on that. I realized that fortran does not give to many options in plotting and i am desperatly trying to convert my code into matlab. I have used many converters. I managed to convert from fortran 77 to fortran 90 but i fail to do so on Matlab :frown:
 
  • #13
Perhaps this may help to open some doors:

Code:
      CHARACTER s*4        ! create string variabel 4 characters long 
      DO 10 i=1,5
        WRITE(s,20) i      ! convert integer i to string in s using format in 20
        PRINT *, 'kk'//s//'.dat' ! concatenates 'kk' plus s plus '.dat'
   10 CONTINUE
   20 FORMAT(I4.4)
      END

This should print a list of file name that have an incrementing number in it, i.e.
kk0001.dat
kk0002.dat
kk0003.dat
kk0004.dat
kk0005.dat

I must admit to being a bit lost as to you actual problem however.
 
  • #14
Thanks again vor your answer! It was helpful. The thing is that i have a code in fortran 77 that is giving me some data on external files every time i run it. It is a simulation of a flow. At first i was trying to create additional code so every time the program will give me a new notepad file with external data then the target file that contains the initial data will change its name into the name of the external data file. Then the program would run again but with different initial data ( as now the initial data will be the results data from the first run of the program) and would give me a different external data. And i wanted this to go on for 10 times in order to get 10 files with external data. But then i decided that instead of using excel to plot my data i could translate into MATLAB and do it a lot easier. So i managed to convert the code from fortran 77 to fortran 90 but i can not manage to translate into MATLAB
as i am using f2matlab converter.
 
  • #15
I want to calculate sum of square of two matrix in fortran . how can I do that using " sum function".
 
  • #16
Hi dear
i want to write a " if command" whit fortran which is too long.

could you please what can I do?

thanks a lot
 
  • #17
Hi dear
i want to write a " if command" whit fortran which is too long.

could you please what can I do?

thanks a lot
 
  • #18
You need to be more specific about what you are trying to do.

Also, instead of tacking your question onto the end of a thread that is almost three years old, it's better to start a new thread.
 
  • #19
Hi Mark44
I didn't know what do you mean?

could you please explain more clearly.

best
 
  • #20
Could you explain more clearly what you are asking for?
Somy_sOMY said:
i want to write a " if command" whit fortran which is too long.
I have no idea what you are asking.
 

1. What is "Execute Excel File w/Fortran Compiler Code"?

"Execute Excel File w/Fortran Compiler Code" is a process in which a Fortran compiler is used to create an executable file that can run on an Excel spreadsheet. This allows for the integration of Fortran code into Excel, allowing for more complex calculations and data analysis.

2. How is "Execute Excel File w/Fortran Compiler Code" different from traditional Excel functions?

The traditional Excel functions are built-in formulas that perform specific calculations or actions on data within a spreadsheet. "Execute Excel File w/Fortran Compiler Code" involves creating a customized executable file that can perform more complex calculations and analysis.

3. Can any Fortran compiler be used for "Execute Excel File w/Fortran Compiler Code"?

No, only certain Fortran compilers are compatible with Excel. Some popular options include Intel Fortran Compiler and GNU Fortran Compiler.

4. What are the benefits of using "Execute Excel File w/Fortran Compiler Code"?

Using "Execute Excel File w/Fortran Compiler Code" allows for more advanced calculations and analysis to be performed within Excel, without the need for complex macros or add-ins. It also allows for easier integration and sharing of Fortran code with other Excel users.

5. Are there any limitations to using "Execute Excel File w/Fortran Compiler Code"?

One limitation is that the resulting executable file may not be compatible with all versions of Excel. Additionally, creating and editing the Fortran code may require a certain level of programming knowledge and experience.

Similar threads

  • Programming and Computer Science
Replies
0
Views
215
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
2
Views
907
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
350
  • Programming and Computer Science
Replies
7
Views
634
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
8
Views
2K
Back
Top