qt生成word文档(wps),代码如下

这是我自己写的,建议往下滑,大佬写的很清楚,我的代码只是人家的一个摘抄部分

链接:https://pan.baidu.com/s/1MgG_dO8hCUi7ErQnOncNOg?pwd=1234 
提取码:1234

使用方法:

#include "ExportReport.h"
ExportReport* w = new ExportReport();
w->show();

在这里插入图片描述
在这里插入图片描述
特别鸣谢大佬为后人指路,本代码是从github而来
原作者在这里:
https://github.com/Kratos-Coder-Hash/QtWordDemo.git
在这里插入图片描述
直接搜关键字:qt word
在这里插入图片描述
如果网速很慢,我已把他的项目暂存百度网盘

链接:https://pan.baidu.com/s/1vYBkapxTMoS66G4bcAnMFg?pwd=1234 
提取码:1234
  • 15
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Qt生成Word文档,你可以使用QtQTextDocument类和QTextCursor类来完成。下面是一个简单的示例代码,演示如何创建一个带有文本和表格的Word文档: ```cpp #include <QApplication> #include <QTextDocument> #include <QTextCursor> #include <QTextTable> int main(int argc, char *argv[]) { QApplication app(argc, argv); // 创建一个QTextDocument对象 QTextDocument document; // 创建一个QTextCursor对象,并将其绑定到文档上 QTextCursor cursor(&document); // 在文档中插入文本 cursor.insertText("这是一个示例文档\n\n"); // 在文档中插入表格 QTextTableFormat tableFormat; tableFormat.setBorder(1); tableFormat.setCellPadding(10); tableFormat.setAlignment(Qt::AlignHCenter); QTextTable *table = cursor.insertTable(3, 2, tableFormat); table->cellAt(0, 0).firstCursorPosition().insertText("表头1"); table->cellAt(0, 1).firstCursorPosition().insertText("表头2"); table->cellAt(1, 0).firstCursorPosition().insertText("内容1"); table->cellAt(1, 1).firstCursorPosition().insertText("内容2"); table->cellAt(2, 0).firstCursorPosition().insertText("内容3"); table->cellAt(2, 1).firstCursorPosition().insertText("内容4"); // 保存文档为Word格式 QString fileName = "example.docx"; QFile file(fileName); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextDocumentWriter writer(&file, "plaintext"); writer.setFormat("odf"); writer.write(&document); } file.close(); return 0; } ``` 这段代码会创建一个带有文本和表格的Word文档,并将其保存为"example.docx"文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值