output to *.xls

S

SS

I'd like, instead of outputting to a *.csv file to output the results from
the code below to an excel sheet.
I changed the datafile extension to read *.xls and it outputs the data but
does not put it into seperate cells
all i get is a coulmn of pairs of results seperated by a comma - i want two
columns of data
can anyone help...
========================================================================

# include <stdio.h>
main ()
{
FILE *datafile;
datafile = fopen ("a:\\lab1-1-1.csv","w");
float Dt = 0.01;
float u = 1;
float Tmax = 2;
float t = 0 , e = 0, y1 = 0, y = 0;
float J = 0.02;
float k = 10;
float B = 0.5;
while (t<=Tmax)
{
e = u - y ;
y1 = y1 +(k* Dt*e);
y = y+Dt/J*(k*y1-B*y);
printf("%7.3f %7.3f \n",t,y);
fprintf(datafile,"%7.3f, %7.3f \n ", t,y);
t = t+Dt;
}
fclose (datafile);
return 0
}
 
R

Rob Thorpe

SS said:
I'd like, instead of outputting to a *.csv file to output the results from
the code below to an excel sheet.
I changed the datafile extension to read *.xls and it outputs the data but
does not put it into seperate cells
all i get is a coulmn of pairs of results seperated by a comma - i want two
columns of data
can anyone help...
========================================================================

# include <stdio.h>
main ()
{
FILE *datafile;
datafile = fopen ("a:\\lab1-1-1.csv","w");
float Dt = 0.01;
float u = 1;
float Tmax = 2;
float t = 0 , e = 0, y1 = 0, y = 0;
float J = 0.02;
float k = 10;
float B = 0.5;
while (t<=Tmax)
{
e = u - y ;
y1 = y1 +(k* Dt*e);
y = y+Dt/J*(k*y1-B*y);
printf("%7.3f %7.3f \n",t,y);
fprintf(datafile,"%7.3f, %7.3f \n ", t,y);
t = t+Dt;
}
fclose (datafile);
return 0
}


This is offtopic, go to comp.os.ms-windows.programmer.*

and they will tell you that the Excel file format has never been
released by Microsoft. You must reverse engineer it, or find some
code that already has.
 
C

CBFalconer

SS said:
I'd like, instead of outputting to a *.csv file to output the
results from the code below to an excel sheet. I changed the
datafile extension to read *.xls and it outputs the data but
does not put it into seperate cells all i get is a coulmn of
pairs of results seperated by a comma - i want two columns of
data can anyone help...
.... snip ...

printf("%7.3f %7.3f \n",t,y);
fprintf(datafile,"%7.3f, %7.3f \n ", t,y);

Tou have output text. For anything else, you first need to define
the output format required. What is a .csv file. What is an
excel sheet. What is a .xls file. What is a cell. Enquiring
minds want to know. Be detailed and specific. All things that
are not defined in the C standard are not known here on c.l.c.
 
D

Default User

This is offtopic, go to comp.os.ms-windows.programmer.*

and they will tell you that the Excel file format has never been
released by Microsoft. You must reverse engineer it, or find some
code that already has.


Or use the work already done by others. This (and most other file format
questions) can be resolved at

http://www.wotsit.org/



Brian Rodenborn
 
G

gswork

SS said:
I'd like, instead of outputting to a *.csv file to output the results from
the code below to an excel sheet.
I changed the datafile extension to read *.xls and it outputs the data but
does not put it into seperate cells
all i get is a coulmn of pairs of results seperated by a comma - i want two
columns of data
can anyone help...

You either have to learn about Excel formats and get more involved in
windows specifics (making a win32 group more appropriate) or stick
with .csv as a text file

You can get quite are with a csv if you are willing to forego
formatting etc.

Something simple like:

20
10
=a1+a2,5,=a3*b3

works ok. You could also explore other text format, xml, for
instance that Excel or some other spreadsheet may be able to deal with

Then your c program issues will pertain only to text manipulation and
questions of standards and correctness.
 
N

Nils Petter Vaskinn

I'd like, instead of outputting to a *.csv file to output the results from [write excel from c]
can anyone help...

Yes.

Step 1 for all alternatives: Know that the filename means nothing to C and
that _you_ have to make a program save in a specific format.

Alt 1: leave the program unchanged, import the file into some spreadsheet
that can save to excel format, save.
Alt 2: Pay Microsoft. Get specification or library or something you can
use. Move on to ms specific newsgroup.
Alt 3: Reverse engineer file format.
Alt 4: Locate specification or library or something you can use from
someone that has already reverse engineered the file format.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,139
Messages
2,570,806
Members
47,352
Latest member
Maricruz09

Latest Threads

Top