View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ed[_31_] Ed[_31_] is offline
external usenet poster
 
Posts: 34
Default .xls to array in c++

Gautam,

If it just has to be done once the easy way is to write it out from
Excel in
CSV format. Then use get() to read the file a character at a time,
putting them
into a char a[], looking for a comma. Once the comma is found,
manipulate the characters
in a[] as needed. E.g., use atoint() or something to convert to
integer.

Here is an example of reading characters.

#include <iostream.h

#include <fstream.h

int main()

{

ifstream inFile("test.txt", ios::in);

if(!inFile){

cerr << " File " << "test.txt" << " could not be opened for input." <<
endl;

}

ofstream outFile("out.txt", ios::out);

if(!outFile){

cerr << " File " << "out.txt" << " could not be opened for output." <<
endl;

}

char c;

while((c = inFile.get()) != EOF ){

outFile.put(c);

}

Here, the characters are just being echoed to outfile rather than
being stored in an array.

Hope this gives you some hints, but not the complete assignment!

Good luck,

Ed
"Gautam" wrote in message
ups.com...
Hi!
I am writing this program in visual c in which i need to take values
which are in an excel spreadsheet (or from .csv format (whichever is
easier!)) and put it into an array for doin some further
computation.
I dont need to write any data into the excel sheet. I just need the
values frm there.
I have the .xls or .csv file ready with its name and location known
already.

Im not an advanced programmer or anything of the sort so please tell
me
what header files to include as well!!!

Thanks in advance

Gautam