Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to read .xls sheet from C program?

Reply
Thread Tools

How to read .xls sheet from C program?

 
 
Rajshekhar
Guest
Posts: n/a
 
      05-26-2005
hi all,
i would like to know how to read .xls file using fopen & getc
combination
(usual procedure thats follwd for read file)..
any ptrs or any function that anybody can suggest??

Rajshekhar

 
Reply With Quote
 
 
 
 
Michael Mair
Guest
Posts: n/a
 
      05-26-2005
Rajshekhar wrote:
> hi all,
> i would like to know how to read .xls file using fopen & getc
> combination
> (usual procedure thats follwd for read file)..
> any ptrs or any function that anybody can suggest??


Your request has nothing to do with the C language itself,
thus it is not within the scope of this newsgroup. If you had
implemented a function to parse a XSL file and it would
not work, you could come here and ask.

<OT>
If you want to do it yourself, get the XML and XSL specs from
w3.org and parse the files accordingly; I would try implementing
it using a state machine.
Or: You can look for libraries which can parse XML files and write
your own XSL stuff.
Or: You can look for libraries directly handling XSLT or XSL:FO.
</OT>

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      05-26-2005
"Rajshekhar" <(E-Mail Removed)> wrote:

> i would like to know how to read .xls file using fopen & getc
> combination
> (usual procedure thats follwd for read file)..
> any ptrs or any function that anybody can suggest??


Yes. You don't want to use getc() on Excel files at all, because they're
binary, not text files. What you want to do is fopen(xlsfile, "rb"), and
then use fread() on it. Actually, strictly speaking you can use getc(),
it just isn't as clean.
As for the file format, <http://www.wotsit.org/> is the usual
recommendation.

Richard
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      05-26-2005

"Rajshekhar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> hi all,
> i would like to know how to read .xls file using fopen & getc
> combination


#include <stdio.h>

int main()
{
FILE *fp = fopen("file.xls", "rb");
if(fp)
{
while(getc(fp) != EOF)
;
if(!feof(fp))
puts("Error reading input");
}
else
puts("Cannot open input");

return 0;
}

-Mike


 
Reply With Quote
 
Michael Mair
Guest
Posts: n/a
 
      05-26-2005
Michael Mair wrote:
> Rajshekhar wrote:
>
>> hi all,
>> i would like to know how to read .xls file using fopen & getc
>> combination
>> (usual procedure thats follwd for read file)..
>> any ptrs or any function that anybody can suggest??

>
>
> Your request has nothing to do with the C language itself,
> thus it is not within the scope of this newsgroup. If you had
> implemented a function to parse a XSL file and it would
> not work, you could come here and ask.
>
> <OT>
> If you want to do it yourself, get the XML and XSL specs from
> w3.org and parse the files accordingly; I would try implementing
> it using a state machine.
> Or: You can look for libraries which can parse XML files and write
> your own XSL stuff.
> Or: You can look for libraries directly handling XSLT or XSL:FO.
> </OT>
>
> Cheers
> Michael


Gaaa... No newsgroups before caffeine (xsl<->xls).

--
E-Mail: Mine is an /at/ gmx /dot/ de address.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      05-26-2005
Mike Wahler wrote:
> "Rajshekhar" <(E-Mail Removed)> wrote in message
>
>> i would like to know how to read .xls file using fopen & getc
>> combination

>
> #include <stdio.h>
>
> int main()
> {
> FILE *fp = fopen("file.xls", "rb");
> if(fp)
> {
> while(getc(fp) != EOF)
> ;
> if(!feof(fp))
> puts("Error reading input");
> }
> else
> puts("Cannot open input");
>
> return 0;
> }


Just as an illustration of what I consider clear code, consider the
following reformatting, which preserves the input (ch) and a handy
place (continue) to insert user code:

#include <stdio.h>

int main(void)
{
FILE *fp;
int ch;

if (!(fp = fopen("file.xls", "rb") puts("Cannot open input");
else {
while (EOF != (ch = getc(fp))) {
continue;
}
if (!feof(fp)) puts("Error reading input");
}
return 0;
}

although my taste would relegate the entire while loop area to a
separate function, as in:

#include <stdio.h>

int process(FILE *fp)
{
int ch;

while (EOF != (ch = getc(fp))) {
continue;
}
return feof(fp);
}

int main(void)
{
FILE *fp;

if (!(fp = fopen("file.xls", "rb") puts("Cannot open input");
else if (!process{fp) puts("Error reading input");
return 0;
}

There are now three versions above. Consider how you would modify
each one to use command line specified files, or a list of files,
or to display some subset of the file information, assuming you had
never seen the code before, and that you want to leave the code
clearly readable.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


 
Reply With Quote
 
Paul Mesken
Guest
Posts: n/a
 
      05-26-2005
On 25 May 2005 23:24:44 -0700, "Rajshekhar" <(E-Mail Removed)>
wrote:

>hi all,
>i would like to know how to read .xls file using fopen & getc
>combination
>(usual procedure thats follwd for read file)..
>any ptrs or any function that anybody can suggest??


This is all very off-topic, of course

If you want to play around with the file itself then follow Richard's
suggestion but if you just want to read from and write to Excel files
from within your application (to make reports, for example) or even
launch Excel in your application then use OLE automation, it's far
less work.

Here are some links :

http://support.microsoft.com/kb/196776
http://support.microsoft.com/default...b;en-us;216686

It's all very much a C++ thing. There's also a mysterious C API :

http://msdn.microsoft.com/archive/de...html/SF7D9.asp

Since I use Borland Builder, I use VCL functions like
GetActiveOleObject, OlePropertySet, etc. A search for these on Google
(adding "Excel" to the search) will return Builder (and Delphi) code
examples (that's how I learned to work with Excel from within my
applications

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
read a excel sheet using aspose.excel sajithkahawatta ASP .Net 3 04-19-2007 02:54 PM
Firefox screwing with my style sheet margins! Bill Firefox 14 11-18-2005 03:30 PM
excel sheet in asp.net using vb sivashankar rajaram ASP .Net 3 03-08-2005 06:44 AM
CSS Sheet not being read for some reason?? cayenne HTML 6 11-25-2003 03:59 PM



Advertisments