How to read a .xls file?

Posted on 2004-08-10
Last Modified: 2008-01-09
I need to open an excel file and then read each row of the file, how do I do this?
Question by:prasen120998
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11769039
Need to be in pure C?
There are many examples in Visual C++:
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11769048

Also you can save a spreadsheet in Comma-Separated-Values format (.csv) and read as a simple text easily.
LVL 22

Expert Comment

ID: 11771616
Above you'll see several ways to do it, mostly very cumbersome.

It's not easy to directly read the file, as it's ina rather convoluted BIFF format.  Plus there are about 8 different Excel file formats, it seems each version of Excel has changed things around a bit.

If you gotta do it, get the BIFF document from and read up on the various file formats.  Plan to spend a good week writing code.

Alternatives include:  send DDE commands to a copy of Excel, have Excel write out a comma-delimited text file, or forget the whole thing.

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.


Expert Comment

ID: 11774296
The best possibility (as jaime olivares already said) is to save the Excel file as .csv (with ';'  or 'tab' as field separator.)
Then you could simply read the file character by character to the end of each line. (line end has ascii code 10 or 13 - whatever excel uses; tab has ascii code 9)

#include <stdio.h>
#include <stdlib.h>

   FILE *in;
   in = fopen ("yourfile.csv","r");
   while ((c=getc(in))!=EOF)  //read to EndOfFile
      i=c;      //get ASCII value of current letter
      if (i!=10)      //read to end of line
         if (i!=9) //read to next tab
      else //end of line reached

Maybe you could tell what you want to do with the Excel File (Copy its content to the console, copy to another file, ...)


Author Comment

ID: 11815530
The excel file would be provided by another system, & my program needs to read that file and create an output

Accepted Solution

modulo earned 0 total points
ID: 12902868
PAQed with points refunded (50)

Community Support Moderator

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now