How do I get my fortran output into excel? - excel

After running a model in fortran (95) I end up with some result arrays (and one result matrix). I'd like to move these into excel for reporting purposes. What's the easiest way to do this?

As S. Lott said before me, CSV format is probably the best choice, but actually Excel is pretty clever about file formats. It will usually work with tab separated or space separated data, or even HTML tables. Try copy-and-pasting your data into Excel to see whether it can work it out, before worrying too much about the format.

Fix your Fortran output to be in CSV format. This is easily imported into a spreadsheet.

You can also write your data into a text file with the below code and then copy paste its contents to excel
before working with these data you must run "paste special wizard" to separate columns of the data in the excel
dimension a(100)
open (25,'output.txt')
do i=1,100
write(25,*) a(i)
end do

Related

How to record data automatically on excel that is generated on Matlab

I am new to MATLAB and I currently have a script that generates different values for a variable n every seconds. So I end up with 100s of data that needs to be transferred to excel. Currently, I do this manually by copying pasting each but it does take really long.
I thought about using xlswrite command but that just writes data on the first column and keeps overwriting that column as new data is generated.
Would you be able to help me or lead me to easier way with this?
If you really want to write directly to excel while your code runs, you can use activex. Some well documented example code can be found in this answer. Somewhere in the middle you find this code:
% select a 5x5 range, and fill it with some numeric values
sheet.Range('A1:E5').Value = num2cell(magic(5));
Here you have replace it with a loop which continuously writes the data.
Be careful when using this solution.
Problems with Excel can stop your MATLAB process
Especially with large data it will be much slower than post-processing
You are forced to have Excel and MATLAB on the same PC installed
Using a simple text file which is continuously written might be the better choice, either fprintf(use the same file handle and it will append) or dlmwrite(use append option).

Generating file which can Excel easily open and save

i am exporting data from database to file, which can Excel read and save.
(CSV) I generate csv, with default format (according to RFC 4180, comma delimeter). As expected, stupid excel read all data and place it to one cell.
(CSV with semicolon delimeter), this one excel read fine, but after change some value and press save (CTRL+S), stupid excel saved it to unreadable file (well done!). No delimeters, no string separators. Ok, so i tried to save it as (CSV format with SEMICOLON delimeter), saved file looks ok, but after opening it with excel, error message was showed - INCORRECT FORMAT - no cell found :D really?!
Generating .xsl file in php. It take too much RAM (about 2GB), so it cant be used.
Do you know any good format, which can excel easily open and easily save?
Thanks a lot!
This question is off-topic, but IMHO Excel 2002/2003 XML Format would be the best choice in your circumstances.
The reason for this is that the data in this format is typed - so you will not see numbers misinterpreted as dates, or phone numbers with leading zeros stripped. I am not aware of the kind of problems you describe, so I cannot say for sure how those will be affected.

How to export data from spss to excel with out nulls

I have a large data set in SPSS (v20) with null values for some observations.
I tried saving as an excel 2007 file, but when I open excel file "#NULL!" appears in cells where values are null. I'm going out of ram when trying to use 'find and replace' function in Excel.
T tried saving as a csv file then I got a space in the cells where values are null.
Could anybody advice on this please?
I typically save as CSV and then in excel save as .xlsx. All missing values are then, as you noted, allocated a space which I accept as representing sysmis values.
When I work with a file that has been saved directly to Excel, (ie many "#NULL" values), I use a VBA macros which does a find/replace row by row. The macro is quicker than doing it all at once as this typically starts to slow to infuriating speeds. The macro is still not as fast as one would want...which is why I go via CSV.
According to the command syntax reference, #NULL! values occur only for system missing values. So to prevent that you need to assign the system missings a value - for that you can use the RECODE command (e.g. RECODE MyVar (SYSMIS = -9)(ELSE = COPY). would work for a number field in which -9 can not be a valid value).
Depending on what you want the value to be when written to the sheet, you can then use the /CELLS=VALUES subcommand on SAVE TRANSLATE to save the assigned missing numeric category (IMO a bad idea for spreadsheets) or you can assign the missing value a VALUE LABELS and use /CELLS=LABELS to save the string label in the cell.

Reformat Data from CSV file

i have data from a csv file. One Column contains Text like "0.2.11" which i need to reformat to "00.02.0011", the leading zeroes and the length of the dot seperated parts are crucial. These are no dates, just random Numbers. How can i reformat those?
Thanks.
I know that this is an insanely long formula, but I believe it will do what you're looking for:
=IF(LEN(IF(ISERR(FIND(".",A1)),A1,LEFT(A1,FIND(".",A1)-1)))=2,IF(ISERR(FIND(".",A1)),A1,LEFT(A1,FIND(".",A1)-1)),"0"&IF(ISERR(FIND(".",A1)),A1,LEFT(A1,FIND(".",A1)-1)))&"."&IF(RIGHT(MID(A1,FIND(".",A1)+1,2))<>".",MID(A1,FIND(".",A1)+1,2),"0"&LEFT(MID(A1,FIND(".",A1)+1,2),1))&"."&IF(LEN(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))=4,RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),IF(LEN(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))=3,"0"&RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),IF(LEN(RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))=2,"00"&RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))),"000"&RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,".","*",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))))))
It's probably long enough that you'd have to save this in one of the new Excel formats like .xlsx or .xlsm for it to save. If you have trouble with it let me know, I also have the formula broken out into several cells (or steps) if you need it that way.
There is a shorter (but still ugly) Excel formula using TEXT function for formatting:
=TEXT(MID(A1,1,FIND(".",A1)-1),"00") &"."& TEXT(MID(A1,FIND(".",A1)+1,FIND(".",A1,FIND(".",A1)+1)-FIND(".",A1)-1),"00") &"."& TEXT(RIGHT(A1,LEN(A1)-FIND(".",A1,FIND(".",A1)+1)),"0000")
I would like to point out there are other methods of solving the same problem. If you have lots of big csv files you might consider preprocessing before importing into Excel. For example, doing the same job in awk is trivial:
BEGIN {
while(getline < "e.csv") {
split($1,a,".");
printf("%02d.%02d.%04d\n",a[1],a[2],a[3]);
}
}
Gawk works well with Windows. After installing, you can run it on the Windows or PowerShell command line as .\awk -f x.awk where x.awk is the above code in a text file.

VBA - Pretty Print a Row in Excel

I want to print a row in Excel.
One row contains data for one project.
I want to print one row on one page nicely formatted. Meaning the value of one cell is the header and should be printed fat and centred, the other values should also be placed at fixed positions on the page.
Is this with VBA possible? When I was searching for this problem I only found results for printing a worksheet or a table or parts of it, but no results to use the values of the cells and formatting them.
Thanks in advance
As the other answers indicate, it is certainly possible in Excel VBA, but it is not really Excel's strong point.
What would typically be done to obtain the result you seem to be after is use a fully formatted Word document with fields that are then filled in with values from an Excel worksheet. You can even cheat a bit and use the Mail Merge \ Letter wizard to set everything up.
If you do want to do it all in Excel, you can find instructions and an example VBA macro here:
http://www.tek-tips.com/faqs.cfm?fid=4223
Template is a good way to do. With a macro there's better performance where it avoids the usage of volatile functions such as INDIRECT() However again it depends on how many volatile functions your worksheet carries.
Yes, it is possible when you use the Styles in excel. I know you can do Font formatting quite easily. Not sure about indenting it, but worth a try.
If style doesnt support it (it might in Excel 2010), you can always indent it via VBA (record a macro when you indent the values , it should look like this):
Selection.InsertIndent 1

Resources