当前位置:网站首页>QT (35) - operate excel qxlsx qaxobject

QT (35) - operate excel qxlsx qaxobject

2022-06-25 00:59:00 Cloudy summer

Reading and writing EXCEL It's a routine operation .QT5 Previous versions use QAxObject operation EXCEL, The disadvantage is that the system must be equipped with OFFICE perhaps WPS.QT5 You can use it Qxlsx 了 , The advantage is that the system does not need to be installed OFFICE perhaps WPS.
Use Qxlsx There are two ways :
1. hold bin,lib,include Join the system environment
2. Directly into the project . I prefer to join the project directly . The second method is given in this paper .

1. Download library files
2. Create project
3. Copy the library file to the project
4. Modify the configuration .pro file + Add header reference


 


1. Download library files :
my demo Examples and library files , For download .

QT,EXCEL,QXLSX-C++ Document resources -CSDN download
2. Create project


3. Copy the library file to the project

 
4. Modify the configuration .pro file + Add header reference


    
 

DEFINES += QT_DEPRECATED_WARNINGS
QXLSX_PARENTPATH=./         # current QXlsx path is . (. means curret directory)
QXLSX_HEADERPATH=./header/  # current QXlsx header path is ./header/
QXLSX_SOURCEPATH=./source/  # current QXlsx source path is ./source/
include(./QXlsx.pri)

 

 

#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QXlsx::Document xlsx;
    xlsx.write("A1", "Hello Qt!"); // write "Hello Qt!" to cell(A,1). it's shared string.
    xlsx.saveAs("helloqxlsx.xlsx"); // save the document as 'Test.xlsx'

    return 0;
    // return a.exec();
}


 

 

 

 

原网站

版权声明
本文为[Cloudy summer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242006274327.html