473,657 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20329
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*********@gm ail.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*********@gm ail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.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*********@gm ail.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.c om, 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*********@gm ail.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
GetActiveOleObj ect, 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
6389
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 only 2 File buttons with corresponding text fields. The actual guts of the program is a C file that accepts 2 file names as arguments and reads from one file, manipulates the string and writes it to another file. Java and C syntax are very similar....
10
2095
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 numbers. Read in the numbers, print them forward and backward." i dont know How to write C++.
9
6885
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 Enter a number : 30 More numbers (y/n)? n
0
5530
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 reads the contents that are seperated by spaces, not tabs - will never be seperated by tabs as it is output from another program. The contents of the file are essiantlly 3 fields/values # # Text Field 1 will be a number from 1 to 26, Field 2 will...
1
2021
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 determine how many positive and negative values have been read. The program will abort when the user input a zero. I've already made a program but I still can't get it right. I deeply appreciate if you will help me. Here's the program I made: ...
7
1326
by: gsreenathreddy | last post by:
package Anonymous; class Base { public void m1(){ System.out.println("base m1 called"); } }
2
2146
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 code. All I've been able to do so far is to get the file read in. Program: Write a code that will read in a text file (which contains a list of words and their definitions, separated by a hyphen). The data read in will be stored into an array. Then...
1
9357
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, sToDirectory);
1
4340
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 You Please Tell Me how to Check/Read Excel Sheet name at runtime.. Thanking you
0
8399
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.