Ok, so I am trying to make this code read a name and grades from an .xlsx file. In this code all it does when I cout << fileName, it doesn't output anything. I don't think that my code is even reading the file. help?
xlsx is extremely complex: fonts, colors, macros, formulae, data, data element types, and a billion other things are jacked into a complex binary format.
export the file as csv is the easy way out for most spreadsheet work. If that won't do, you need either a ton of work or to use a library to read this format.
I see that you have realized that you can not read an ".xlsx" file directly. Now you have to understand how to read a ".csv" file, much easier.
Given an input file something like:
John Doe,90,90,A\n // '\n' to indicate a new line or end of line
understand that each comma separates a field and you need to read each field separately.
So instead of getline(in, line); you would need to do something like:
1 2 3 4
std::getline(in, studentName, ',');
std::getline(in, total,',');
std::getline(in, percentage, ',');
std::getline(in, letterGrade); // <--- Being last the third parameter is not needed
After this any numerical value would have to be changed from a string to whatever you need it to be.
When this is working the way you want, put these lines in a while loop with the condition being the first line of code without the ";".
I have a couple of programs that read an Excel ".csv" file and process the data.
Thanks Andy, but what I was doing was just testing to see if it would read the first line of info. It won't, I am wondering if I am saving the csv file wrong, or what. The problem is that when I try to read and display even the first string of information it wont show anything. That is the real problem that I am facing. Also when I save my file as a .csv, then reopen the file it has the same layout as the .xlsx, so I was wondering if I might be saving it wrong.
In my version of Excel, 2010 version, there are three versions for saving a ".csv" file I believe I use the first version that says "CSV (comma delimited) (*.csv)". If that makes any difference for you.
I see what you are trying and there should be no reason that your test should not work. What I can think of right now is for you to post a portion, 3 or 4 lines, of the "csv" file so I can see what you are working with. The "csv" file is just a plain text file, so it should not be a problem.
Post a sample of the "csv" file and I will see what I can come up with.