Skip to content

Latest commit

 

History

History
139 lines (82 loc) · 2.92 KB

File metadata and controls

139 lines (82 loc) · 2.92 KB

如何设置 QXlsx 项目

以其他语言阅读: English, 한국어, 简体中文

  • 以下是应用 QXlsx 的简单方法。
  • 本文适用于使用 qmake 构建项目。若使用 CMake,请参考 English文档中文文档.
  • 以下步骤基于 Windows 系统,Linux 或 macOS 的流程类似。
  • 在 Linux 或 Mac 上应用它的方法是类似的,- 如有特殊需求,我会补充说明或提供帮助。
    • Hi! I'm j2doll. My native language is not English and my English is not fluent. Please understand. :-)

设置步骤

1️⃣ 从 github 克隆源代码

git clone https://github.com/j2doll/QXlsx.git



2️⃣ 启动 Qt Creator



3️⃣ 创建一个新的 Qt 项目。



4️⃣ 本示例为控制台应用程序。



5️⃣ 设置项目名称(示例:HelloQXlsx)。



6️⃣ HelloQXlsx 项目创建完成。



7️⃣ 查看项目目录结构



8️⃣ 复制 QXlsx 到项目目录

xcopy c:\workspace\github\QXlsx\QXlsx c:\workspace\HelloQXlsx /s /e

> 将 QXlsx 源码复制到你的 Qt 项目中(请根据你本机路径修改)



9️⃣ 项目的当前目录和文件



🔟 在Qt项目文件(*.pro)中添加 QXlxs 库的代码

# QXlsx code for Application Qt project
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)



1️⃣1️⃣ 设置示例的头文件和命名空间。然后附加 hello world 代码。

// main.cpp

#include <QCoreApplication>

#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("Test.xlsx"); // save the document as 'Test.xlsx'

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



1️⃣2️⃣ 构建并运行项目



1️⃣3️⃣ 生成可执行文件(*.exe)和Excel文件(.xlsx)。