| | |
Read Spreadsheet Data for math?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2005
Posts: 67
Reputation:
Solved Threads: 1
Hello. I hope not to annoy you with such a question.
I'd like to read cell data from specific columns within a spreadsheet. I'm trying to read data within the following format (from the .xls file I'm analyzing).
Lets say I'd like to get the average of all of the numbers within the second column? How would I go about doing that? I understand that the comma is used as a delimiter within the rows to separate the cell's association with the columns. How would I go about reading each value after the program encounters the delimiter? I want to use each value for a something mathematical, so I imagine I'd need to store each value as a number somehow.
Main Idea:
-I'd like to read each cell from a column.
-I'd like to use the values within each cell to find an average.
Can someone please help me in doing this?
I thank you very much.
I'd like to read cell data from specific columns within a spreadsheet. I'm trying to read data within the following format (from the .xls file I'm analyzing).
C++ Syntax (Toggle Plain Text)
Wavelength (nm),Absorbance (AU),Std.Dev. 190,-0.333324432373047,0.187723662173536 191,-0.184257030487061,0.169325912513228 192,0.0989446640014648,0.243154257457939 193,-0.196856021881104,0.322099862671817 194,0.0530929565429688,0.250335468281439 195,0.146337985992432,0.301110817821903 196,0.0579915046691895,0.359937145256163 197,-0.309549331665039,0.293385120791022 198,-0.396398544311523,0.2578125
Lets say I'd like to get the average of all of the numbers within the second column? How would I go about doing that? I understand that the comma is used as a delimiter within the rows to separate the cell's association with the columns. How would I go about reading each value after the program encounters the delimiter? I want to use each value for a something mathematical, so I imagine I'd need to store each value as a number somehow.
Main Idea:
-I'd like to read each cell from a column.
-I'd like to use the values within each cell to find an average.
Can someone please help me in doing this?
I thank you very much.
Its almost impossible to read .xls files directly because they contain proprietary MS-Excel data. But if you really really really have to do it then read this document
The simpler solution is to convert the xls files to cvs files using MS-Excell program. The csv files do not contain all that binary data and reading is straight forward.
The simpler solution is to convert the xls files to cvs files using MS-Excell program. The csv files do not contain all that binary data and reading is straight forward.
•
•
Join Date: Jul 2005
Posts: 67
Reputation:
Solved Threads: 1
•
•
•
•
Its almost impossible to read .xls files directly because they contain proprietary MS-Excel data. But if you really really really have to do it then read this document
The simpler solution is to convert the xls files to cvs files using MS-Excell program. The csv files do not contain all that binary data and reading is straight forward.
The great thing about this project is that there isn't anything that has to do with MS-Excel at all in the spreadsheets I'm working with.
C++ Syntax (Toggle Plain Text)
Wavelength (nm),Absorbance (AU),Std.Dev. 190,-0.333324432373047,0.187723662173536 191,-0.184257030487061,0.169325912513228 192,0.0989446640014648,0.243154257457939
The data, as you can see, is separated by commas, and there is no other data to specify any special file conditions that can only be appropriately interpreted by M$ Excel.
*Note: The (nm) is for nanometers, and the (AU) is for gold. Std.Dev. is for Standard Deviation. This was a spectroscopy report.
Last edited by Quan Chi2; Jul 3rd, 2009 at 3:32 pm.
>>The great thing about this project is that there isn't anything that has to do with MS-Excel at all in the spreadsheets I'm working with.
You are not working with xls files as you initially stated, but comma separated csv file. The first line contains cell titles while the remaing lines contain the data.
use getline() to read each line, ignoring the first line read. After that use getline() in conjunction with stingstream to extract second colum, Something like this:
You are not working with xls files as you initially stated, but comma separated csv file. The first line contains cell titles while the remaing lines contain the data.
use getline() to read each line, ignoring the first line read. After that use getline() in conjunction with stingstream to extract second colum, Something like this:
C++ Syntax (Toggle Plain Text)
string line; ifstream in("fiulename.csv"); getline(in, line); // ignore cell titles while( getline(in, line) ) { float n; stringstream str(line); while( getline( str, line, ',') ) { n = atof( line.c_str()); // instead of atof() you could also convert string to float // using another stringstream object, like this: stringstream str1(line); str1 >> n; // now do thatever you want with this cell value } }
Last edited by Ancient Dragon; Jul 3rd, 2009 at 5:19 pm.
![]() |
Similar Threads
- Read Website Data (PHP)
- Are direct system call functions the fastest way to read/write data on Linux? (C++)
- How to read wchar_t data in a file? (C++)
- Get data out of excel file stored as an image (MS SQL)
- VB code to clear entire spreadsheet data (contents) (Visual Basic 4 / 5 / 6)
- how to read a file in C and use the data (C)
- Data in spreadsheet is not printing on same page (Visual Basic 4 / 5 / 6)
- HOW TO READ BULK RAW DATA INTO AN ORACLE-8i SERVER****URGENT**** (Oracle)
- Multiple data being read in (C++)
Other Threads in the C++ Forum
- Previous Thread: Best C++ Compiler
- Next Thread: How to import DLL in visual studio 2005
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






