• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use excel file in C program for file handeling?  RSS feed

 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use excel file in C program to store data & retriving of data.
I can read & write word file. How to read from and write into excel file?

I am sending code for word files.

#include<stdio.h>

struct Employee{
char code[4];
char delim;
char name[10];
};


void main()
{
struct Employee e,e1;
FILE *fp;
printf("Enter the code:");
scanf("%s",e.code);
printf("Enter the name:");
scanf("%s",e.name);
e.delim='\t';
fp=fopen("new.doc","w");

fwrite(&e,sizeof(struct Employee),1,fp);
printf("\n");
fclose(fp);

fp=fopen("new.doc","r");
while(fread(&e1,sizeof(struct Employee),1,fp))
{
printf("%s",e1.code);
if(e1.delim=='\t')
printf(":");
printf("%s",e1.name);

}
printf("\n");
}
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that code really create a file Word can open? DOC and XLS have very complex file formats, which this code seems to ignore entirely.

Since you posted this on a Java discussion site, are you interested in somehow using Java to solve this? If so, you can use JNI to embed a JVM in your C code, and then use one of the Java libraries mentioned here to interact with the file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!