Load data from CSV to excel ranges - C++

For discussion of the xlw project for producing xlls.

Load data from CSV to excel ranges - C++

Postby Vineel » Mon May 06, 2013 6:49 am

How can i load data from CSV file (delimited by comma) to the range of cells in the excel? I want to load this data on click of the button in the menu and using C++.
Vineel
 
Posts: 1
Joined: Mon May 06, 2013 6:42 am

Re: Load data from CSV to excel ranges - C++

Postby colman » Sun May 12, 2013 3:47 pm

hi,

Does it have to be in C++?

This one for C++ looks pretty good:
http://www.libxl.com/
http://sourceforge.net/projects/xlw/

I used this lib for java:
http://jexcelapi.sourceforge.net/resources/javadocs/current/docs/

For the CVS part:
http://www.cplusplus.com/reference/string/string/getline/

Some sample code to give you an idea:
Code: Select all
ifstream file ( "yourdata.csv" );
string value;
while ( !file.eof )
{
     getline ( file, value, ',' );
     cout << string( value, 1, value.length() );
}


or something like the following

Code: Select all
std::ifstream  data("yourdata.csv");

    std::string line;
    while(std::getline(data,line))
    {
        std::stringstream  lineStream(line);
        std::string        cell;
        while(std::getline(lineStream,cell,','))
        {
            // store your CVS data into a container or just work with the excel lib directly to process it
        }
    }


You should end up with a for loop after putting the CVS data into some storage container, like a vector. Your body should be easy to write, something like this:
sheet->writeNum(position_x,position_y,value);


The whole solution isn't here, but I guess you'll get the idea. If you want todo this in a one button click with C++, you may be better off with a simple command driven program? Otherwise I would recommend netbeans for building a small GUI and doing it in java. As its a bit faster for taking care of the fileselector and binding the commands you'll be needing to several buttons and fields (setting input and output file names etc).


- Colman
colman
 
Posts: 8
Joined: Sat Oct 20, 2012 11:10 am
Location: Darmstadt, Germany


Return to xlw

Who is online

Users browsing this forum: No registered users and 2 guests