使用LibXL

时间:2018-12-12 05:47:30

标签: c++ libxl

我正在尝试使用CodeBlocks上名为LibXL [for C ++]的第三方库为我的Mini项目执行此代码。

#include "libxl.h"
#include <iostream>
#include<string>
#include<tchar.h>

#ifdef _UNICODE
typedef WCHAR TCHAR;
#else
typedef char TCHAR;
#endif


using namespace libxl;
using namespace std;
    //Ignore this block of comments //Specifically for CinCout 
/*
class Student_Information
{
    string First_Name, Last_Name,Mobile, Course;
    double bd_day, bd_month, bd_year,Gr_No;

   // Format* format1 = info_book->addFormat();


public:

Student_Information()
{

Book* info_book = xlCreateBook();
Sheet* sheet1 = info_book->addSheet("Sheet1");


}
    void insert_info()
    {
        int num;
        info_book->load("student_information.xls");
}*/

class Student_Information
{
    string First_Name, Last_Name,Mobile, Course;
    int bd_day, bd_month, bd_year,Gr_No;
     Book* info_book = xlCreateBook();  //Throws are warning "non-static data member initializers only available with -std=c++11 or -std=gnu++11"
    Sheet* sheet1 = info_book->addSheet("Sheet1"); //Throws the same warning even over here


public:

    void insert_info()
    {
        int num;
        info_book->load("student_information.xls");

        do
        {
            cout<<"Enter 1 to add a record | Enter 0 to exit";
            cin>>num;

            cout<<"Please enter the GR Number of the Student: ";
            cin>>Gr_No;
            sheet1->writeNum(sheet1->lastRow(),0,Gr_No);

            cout<<"Please Enter your FIRST NAME [In Capitals]: ";
            cin>>First_Name;
            sheet1->writeStr(sheet1->lastRow(),1,First_Name.c_str());

            cout<<"Please Enter your LAST NAME [In Capitals]: ";
            cin>>Last_Name;

            sheet1->writeStr(sheet1->lastRow(),2,Last_Name.c_str());

            sheet1->writeStr(sheet1->lastRow(),3,"BCA");

            cout<<"Please enter your 10 Digit mobile number: ";
            cin>>Mobile;

            sheet1->writeStr(sheet1->lastRow(),4,Mobile.c_str());

            info_book->save("student_information.xls");
        }
        while(num!=0);
       // info_book->load("student_information.xls");


       // info_book->release();

    }
};

int main()
{
    Student_Information ob1;
    ob1.insert_info();
}

当我尝试编译代码时,我收到代码中提到的两个警告,但是编译器未显示错误

执行程序时,程序要求2个选项。当用户选择选项1时,程序会询问GR号。输入GR号后,它会崩溃,在屏幕上显示此消息:

enter image description here

我对此错误感到非常困惑。我尝试清理并重建项目,但无济于事。 我在编码器UTF-8和GNU GCC编译器中使用代码块。

很抱歉,如果我不恰当地提及某些东西而冒犯了21世纪的极客。我对LibXL不太熟悉,并且对通用编码不太熟悉。

1 个答案:

答案 0 :(得分:0)

通过frPdu FR::TEMP_Pdu; on preStart { if (@FR_namespace::TEMP_Enablebutton) { FRSetSendPDU(TEMP_Pdu); } } on frStartCycle * { if (@FR_namespace::TEMP_Enablebutton) FrUpdatePDU(TEMP_Pdu, 1, 1)); } 函数加载该书后,该书的旧内容被删除,并由文件中加载的新内容替换,sheet1将指向无效内容,并使程序崩溃。 / p>

一种快速的解决方案是,每次将图书加载为时,都会找到新的Sheet1值:

load()