![]() |
.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 |
.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 |
.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 |
All times are GMT +1. The time now is 05:17 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com