fortran to excel without deleting existing file
fortran to excel without deleting existing file
(OP)
Hi, I have an excel which is fed with equations on sheet2. from my fortran program, I want to write output on sheet1 of this excel - is this possible. I know how to write the output to excel, unfortunately, it deletes the existing excel and makes a fresh copy in the folder - where by I loose the excel with equations/macros on the sheet2. I want the equations/macros on sheet2 to work on the extracted values on sheet1...appreciate your suggestion on how to write into the same excel file.thanks





RE: fortran to excel without deleting existing file
RE: fortran to excel without deleting existing file
In Excel have a sheet that uses the Import From Text File feature in the Data TAB, to ONE TIME create an import that can be refreshed on command. Your workbook could be configured to refresh that import in the Workbook_Open event, so that the latest data would appear in that sheet each time the workbook is opened.
Skip,
Just traded in my OLD subtlety...
for a NUance!
RE: fortran to excel without deleting existing file
Have a look at: Running exe files from Excel
The process is:
- Create the input data in Excel (if required), and save it to a text file
- Run the program from VBA using the WScript.Shell object
- Read the resulting output files and save to a named range
The Fortran program in my example produces space delimited files, which are read and split into cells using two VBA functions (ReadText and SplitText), which are included in the download file. Let me know if you would like a modified version to read csv files.Following posts look at the process of compiling the Fortran (using GFortran) as an exe file, then compiling as a dll so that data can be passed directly from and to Excel.
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: fortran to excel without deleting existing file
Skip,
Just traded in my OLD subtlety...
for a NUance!
RE: fortran to excel without deleting existing file
I know, but I find the built in import cumbersome to set up, inflexible, and lacking in many features I need, so I wrote my own.
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: fortran to excel without deleting existing file
RE: fortran to excel without deleting existing file
RE: fortran to excel without deleting existing file
RE: fortran to excel without deleting existing file
I've been using this acquisition technique for over 20 years. Set up in a few minutes. It's a ONE TIME TASK. Get data from tables in your own workbook, other workbooks, other databases like Access, Oracle, DB2 and text files: it's very versatile.
Skip,
Just traded in my OLD subtlety...
for a NUance!
RE: fortran to excel without deleting existing file
Alternately, you could simply leave the output file in CSV format, and modify your macro to open the file directly and either automatically copy the data into the macro's workbook, or manipulate the data in situ.
TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers
RE: fortran to excel without deleting existing file
1) Open you spreadsheet
2) Save it as a XML Spreadsheet 2003(*.xml). Let us call this top.xml. Note that there is an xml format further up: don't use that one. Use the one that says XML Spreadsheet.
3) Copy top.xml to bottom.xml
4) Open top.xml in notepad. Look for ss:Name=”Sheet1”. Look further down for the first <row>. Delete from that point to the end of the file. Save and close
5) Open bottom.xml in notepad. Look for ss:Name=”Sheet1”. Look for </Table>. Delete from the line before to the beginning of the file. Save and close
6) Write a program to do the following
b. Copy the entire contents of top.xml to madeup.xml
c. Write out your data in the following format
i. For each row, print <Row ss:AutoFitHeight=”0”>
ii. For each column print <Cell><Data ss:Type=”Number”>x</Data></Cell> where x is the number
iii. To end the row, print </Row>
e. Close madeup.xml