libxl library use in c++

1.6k Views Asked by At

When I create a project visual studio 2015 I can work this libxl library hovewer I could not be able to work that library on visual studio qt gui application project.

I try everything whatever I know.

#include "stdafx.h"
#include "QtGuiApplication5.h"
#include <QtWidgets/QApplication>
#include <qapplication.h>
#include <qpushbutton.h>
#include <iostream>
#include <conio.h>
#include "libxl.h"
using namespacenclude <Qt libxl;
using namespace std;

int main(int argc, char *argv[])
{
    Book* book = xlCreateBook();

    if (book)
    {
        if (book->load(L"..\\Lab_Bus Datebase.xlsx"))
        {
            Sheet* sheet = book->getSheet(0);
            if (sheet)
            {
                const wchar_t* s = sheet->readStr(2, 1);
                if (s) std::wcout << s << std::endl << std::endl;
            }
        } 
        else
        {
            std::cout << "At first run generate !" << std::endl;
        }
        book->release();
    }
    std::cout << "\nPress any key to exit...";
    _getch();
    QApplication a(argc, argv);
    QtGuiApplication5 w;
    w.show();

    return a.exec();
}

Link2019 error: Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol __imp_xlCreateBookW referenced in function main QtGuiApplication5

link1120 error: Severity Code Description Project File Line Suppression State Error LNK1120 1 unresolved externals QtGuiApplication5 C

1

There are 1 best solutions below

6
Mayur On

You need to configure visual studio project properties to use required lib. Refer this link for the same.

You are using .xlsx file so instead of xlCreateBook use xlCreateXMLBook. Apart from this you need to use using namespace libxl;as well

Below are Factory functions:

  • Book* xlCreateBook()
    Create a binary book instance for xls format. This function should be called first for receiving a book pointer. This function and other classes are in libxl namespace.
  • Book* xlCreateXMLBook()
    Create a xml book instance for xlsx format. This function should be called first for receiving a book pointer. This function and other classes are in libxl namespace.

See below image above code works fine at my machine. enter image description here