Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default .xls to array in c++

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default .xls to array in c++

hmmm..thanks that was quite helpful!
But say if i need to import the data from an excel spreadsheet....?
If there is a way to import from excel, isnt it likely to be easier?
since i guess it would recognise the entire floating point number in a
cell instead of requiring to convert it with some command repeatedly
like atof() or smth?

Gautam

Ed wrote:
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex conditional summing - array COUNT works, array SUM gives#VALUE fatcatfan Excel Worksheet Functions 4 November 18th 09 06:41 PM
Prevent cell/array references from changing when altering/moving thecell/array nme Excel Discussion (Misc queries) 1 September 19th 08 01:53 PM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM


All times are GMT +1. The time now is 10:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"