0

I'm relatively new to C++ (I do know the basics and have gone through programs by myself successfully) and am trying to create a project to ease some data processing for tons of information that I need.

The data input is an excel file of 30000 rows and 27 columns. Out of that data I need to extract 4 specific columns (which are always columns 2, 8, 14 and 20) and I would like to put each column into an individual array, the first column should be composed of strings, the second and third of integers and the last one of strings too. Since the first row contains the column description, it would be a good idea to try and omit that first row too. The excel file is currently in '.xlsx' format.

I've spent two whole days researching on this matter and haven't got a clue at where to start. I read converting the file type to '.csv' format and using something named 'stl' could be useful but with the information I have I feel totally unable to do so.

I'm not hoping for someone to solve this for me, I would appreciate if someone could point me in the right direction, either where to look for the information I need or to start me out. Once I manage to get the data read into arrays I actually know how to program the processing, but this part is tricking me.

Thank you for your help and time reading through.

1 Answers1

2

As you said, you can convert the excel file to csv and read it. You'll find a lot of answer on SO on this topic, e.g. How can I read and parse CSV files in C++

Otherwise, you can rely on some external library, such as libxl (just the first result on google :D). You can then read an existing excel like:

Book* book = xlCreateBook();
if(book)
{
    if(book->load(L"example.xls"))
    {
        Sheet* sheet = book->getSheet(0);
        if(sheet)
        {
            const wchar_t* s = sheet->readStr(2, 1);
            if(s) wcout << s << endl;

            double d = sheet->readNum(3, 1);
            cout << d << endl;
        }
    }

    book->release();
}
Community
  • 1
  • 1
Miki
  • 40,887
  • 13
  • 123
  • 202