473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to read .xls sheet from C program?

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

Nov 14 '05 #1
6 20322
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.
Nov 14 '05 #2
"Rajshekhar" <ra*********@gmail.com> 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
Nov 14 '05 #3

"Rajshekhar" <ra*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr 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
Nov 14 '05 #4
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.
Nov 14 '05 #5
Mike Wahler wrote:
"Rajshekhar" <ra*********@gmail.com> 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
Nov 14 '05 #6
On 25 May 2005 23:24:44 -0700, "Rajshekhar" <ra*********@gmail.com>
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 :-)

Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon Wigzell | last post by:
I recently wrote a program with MS Visual Studio C++, sent it off to the client where it didn't run, after some probing I discover they are on a Mac! My program is a MSF interface that is really...
10
by: atlanta | last post by:
this is a simple C++ program to write. "Write a complete and functioning structured program that successfully compiles on Visual C++ 6, that uses two-dimensional array (5x5) that stores...
9
by: ehabaziz2001 | last post by:
I am facing that error message with no idea WHY the reason ? "Abnormal program termination" E:\programs\c_lang\iti01\tc201\ch06\ownarr01o01 Enter a number : 25 More numbers (y/n)? y...
0
by: 14Dallas | last post by:
Hi, I have been working with another programmer to write this code. I haven't written code in years - DBase III and Pascal - anyways, back to my code question. The program opens a file and...
1
aprilmae36
by: aprilmae36 | last post by:
Nice day to all... I'm new in java programming and I'm having some problem with this program. The problem is this: Write a program that will read an unspecified number of non-zero integers and...
7
by: gsreenathreddy | last post by:
package Anonymous; class Base { public void m1(){ System.out.println("base m1 called"); } }
2
by: Prime8 | last post by:
I've been researching so much about arrays and matrices and such, but it hasn't helped me at all on my program. Everything is either over my head or doesn't help with the specific program I have to...
1
by: Matrixinline | last post by:
Hi All, File Text.txt Contains following text as : "C:\program file\application data\details\app" "D:\Program File" I tried to read that data as fscanf(oFp, "%s %s", sCopyDirectory,...
1
by: Manesh Pawar | last post by:
Hello, I a now Porting a data from Uploaded Excel File to database. In that, I need to check "Sheet name" Of that Excel file Whether it is Sheet1 or Sheet2 or something else... Will...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.