Getting the Excel

I'm kind of stuck because I used the code that they posted there and now I don't know hot to get the file inside the Excel to show on the console.
This is the code that I used. Thank you in advance. :)

#include <iostream>
#include <fstream>
#include<string>
#include <iomanip>
#include<windows.h>
#include<conio.h>
using namespace std;
int main()
{
ifstream indata;
ofstream outdata;
string Groom, Bride, Venue, TimE, DatE;
int Guests;
outdata.open("aaaaron.csv", ios::app);
cout<<"Please enter date of the reception (Use dash to separate): ";
cin>>DatE;
cout<<"\nPlease enter time of the reception (Use colon and dash): ";
cin>>TimE;
cout<<"\nPlease enter the name of the groom: ";
cin>>Groom;
cout<<"\nPlease enter the name of the bride: ";
cin>>Bride;
cout<<"\nPlease enter the number of guests: ";
cin>>Guests;
cout<<"\nPlease enter the venue of the reception: ";
cin>>Venue;
outdata<<DatE<<','<<TimE<<','<<Groom<<','<<Bride<<','<<Guests<<','<<Venue;
outdata<<endl;


int x;
indata.open("aaaaron.csv");



system("pause>0");
return 0;
}
So you want to read the csv file and print it in the console?

For this you can use getline:
http://www.cplusplus.com/reference/string/string/getline/?kw=getline

I would probably do 2 getlines. 1 to get the row (the actual line)
and another in a loop to get each column (specify a comma as the delimiter)

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
string line;

// get one line from the csv file
getline( yourcsvfile, line );

// put that line in a stringstream so we can extract from it easily
stringstream ss(line);

// get each column:
string firstcolumn;
getline( ss, firstcolumn, ',' );

// etc, etc 



Alternatively, instead of putting the line in a stringstream, you can use string::find and string::substr to extract the columns. But that's probably a bit more error prone.
You can try using getline along with tokenize

e.g

1
2
3
4
5
6
           string line;
           int index=0;
           getline( filename, line);
            
           string firstcol=line.tokenize("," , index);
           string secondcol=line.tokenize("," , index);

Implement your excel within a mature excel reading application to get the file for console or extract all the contents in the excel file, including chart, graph and other data. Besides, if we want to get the whole excel worksheet containg the file or certain objects, we can extract the certain page out from the whole excel document.

http://www.rasteredge.com/how-to/vb-net-imaging/excel-reading/
http://www.rasteredge.com/how-to/vb-net-imaging/excel-extract-pages/

Topic archived. No new replies allowed.