QT跨平台读写Excel

QT跨平台读写Excel

背景

开发框架QT,makefile构建工具CMake,编译器MinGW

Excel工具

考虑跨平台则不能使用针对微软COM组件的QAxObject来读写Excel,因此使用开源QtXlsx。
这里是将QXlsx当做源码嵌入使用

源码下载链接:
QtXlse-Gitee
QtXlse-Github

CMakeLists.txt

powershell 复制代码
cmake_minimum_required(VERSION 3.5)

#定义工程name
project(Excel_FPD)

# 添加Qt模块
find_package(Qt5 COMPONENTS Core Widgets Gui REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# 设置C++标准
set(CMAKE_CXX_STANDARD 11)

# 定义宏
add_compile_definitions(XLSX_NO_LIB)

# 设置路径变量
set(QXLSX ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/qtxlsx)

# 包含路径
include_directories(${QXLSX})

# 查找QXLSX相关的头文件和cpp文件
file(GLOB QXLSX_HEADERS ${QXLSX}/*.h)
file(GLOB QXLSX_SOURCES ${QXLSX}/*.cpp)


# 添加可执行文件
add_executable(Excel_FPD
    ${QXLSX_SOURCES}
    excelengine.cpp
    main.cpp
)


# 链接Qt模块
target_link_libraries(Excel_FPD
   Qt5::Core
   Qt5::Widgets
   Qt5::Gui
   Qt5::GuiPrivate
)


# 默认部署规则
#if(QNX)
#   set(target_path /tmp/${TARGET}/bin)
#elseif(UNIX AND NOT ANDROID)
#   set(target_path /opt/${TARGET}/bin)
#else()
#    set(target_path ${CMAKE_CURRENT_SOURCE_DIR}/bin)
#endif()

#if(NOT target_path STREQUAL "")
#   install(TARGETS Excel_FPD DESTINATION ${target_path})
#   message("here is target_path ${target_path}")
#endif()

工程目录


这里是将qtxlsxwriter-master\src\xlsx源码直接拷贝到目录qtxlsx下,删除无用的.pro和.pri文件,因为我使用CMake,不使用qmake。

接口使用方法可以参考官方文档

相关推荐
Data-Miner14 小时前
AI和Excel怎么结合才能真提效
人工智能·excel
蓝祁子yoky14 小时前
Qt学习日记 Day15:网络编程(二)- UDP基础
网络·qt·学习
读书札记202215 小时前
Qt UTF-8和UTF-8(BOM)
开发语言·qt
ShineWinsu15 小时前
对于Qt:QProgressBar常见属性的解析
开发语言·c++·qt·进度条·gui·定时器·qprogressbar
ShineWinsu15 小时前
对于Qt:QLCDNumber常见属性以及QTimer的解析
服务器·数据库·c++·qt·gui·qtimer·qlcdnumber
听风吹等浪起1 天前
第26章:ViT+InceptionDW+FocalLoss改进|CT骨折影像二分类完整Pytorch实现(含PyQt5推理GUI)
pytorch·qt·分类
ShineWinsu1 天前
对于Qt:QRadioButton常见属性以及QButtonGroup的解析
数据库·c++·qt·microsoft·gui·qradiobutton·qbuttongroup
sycmancia1 天前
Qml——Image和AnimatedImage使用
qt
taller_20001 天前
【012】数据类型入门: Excel 数据到 Python 值的转换
python·excel·pie·py
lhbweilai1 天前
QT(了解各个控件和布局)上
数据库·qt