C++11 libxl库在c+中的使用+;

C++11 libxl库在c+中的使用+;,c++11,libxl,C++11,Libxl,当我创建一个项目visual studio 2015时,我可以使用这个libxl库,但我无法在visual studio qt gui应用程序项目上使用该库 我知道什么就试什么 #include "stdafx.h" #include "QtGuiApplication5.h" #include <QtWidgets/QApplication> #include <qapplication.h> #include <qpushbutton.h> #includ

当我创建一个项目visual studio 2015时,我可以使用这个libxl库,但我无法在visual studio qt gui应用程序项目上使用该库

我知道什么就试什么

#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();
}
#包括“stdafx.h”
#包括“QtGuiApplication5.h”
#包括
#包括
#包括
#包括
#包括
#包括“libxl.h”
使用名称空间包括加载(L“.\\Lab\u-Bus-Datebase.xlsx”))
{
工作表*Sheet=book->getSheet(0);
若有(第页)
{
const wchar_t*s=sheet->readStr(2,1);

如果std::wcout您需要配置visual studio项目属性以使用所需的库。请参阅链接以了解相同的内容。

您使用的是
.xlsx
文件,因此不使用
xlCreateBook
而使用
xlCreateXMLBook
。除此之外,您还需要使用
名称空间libxl;

以下是:

  • Book*xlCreateBook()

    创建xls格式的二进制图书实例。应首先调用此函数以接收图书指针。此函数和其他类位于libxl命名空间中
  • Book*xlCreateXMLBook()

    创建xlsx格式的xml图书实例。应首先调用此函数以接收图书指针。此函数和其他类位于libxl命名空间中
见下图以上代码在我的机器上运行良好。

未解析的外部符号表示未找到所用函数的定义。可能缺少要链接的库。请使用
#pragma注释(库,“libname.lib”)
我犯了同样的错误。我做了在参考页上写的任何需要的事情,它与xlsx无关,即使我删除了整个代码而没有第一行,我也收到了相同的错误,比如int main(int argc,char argv[]){Book Book Book Book=xlCreateXMLBook();return a.exec();}您确定在您的平台上使用了预期的库吗?例如,尝试将x86库与x86 visual studio build Environment一起使用好吧,我正在我的系统上尝试相同的示例,让我们看看会发生什么事情一切正常,我从Sheet中获取数据我猜您可能错误配置了项目属性。