当前位置: 首页 > news >正文

学做文案的网站企业宣传片制作模板

学做文案的网站,企业宣传片制作模板,建设个人网上银行登录入口官网,网站开发辛苦吗前文的docx生成程序需要预先准备模板文件,不方便。今天找到另一个docx开源库minidocx,它直接生成文件,调用方法也和duckx差不多,非常简单,所以准备迁移到这个库。 我下载的是稳定版本v0.6.0, 原来它需要cma…

前文的docx生成程序需要预先准备模板文件,不方便。今天找到另一个docx开源库minidocx,它直接生成文件,调用方法也和duckx差不多,非常简单,所以准备迁移到这个库。
我下载的是稳定版本v0.6.0,
原来它需要cmake生成Makefile,经过简单分析,发现它与DuckX一样,也是调用的pugixml和zip库,本身的实现只要一个minidocx.h和minidocx.cpp,所以可以直接手写编译命令行如下:

/par/minidocx-0.6.0# g++ -o table examples/basic.cpp src/minidocx.cpp 3rdparty/pugixml-1.13/*.cpp 3rdparty/zip-0.2.1/*.c -I src -I 3rdparty/pugixml-1.13 -I 3rdparty/zip-0.2.1

运行basic果然凭空生成了docx文件。它的源代码如下:

#include "minidocx.hpp"using namespace docx;int main()
{Document doc;auto p1 = doc.AppendParagraph("Hello, World!", 12, "Times New Roman");auto p2 = doc.AppendParagraph(u8"你好,世界!", 14, u8"宋体");auto p3 = doc.AppendParagraph(u8"Hello, 世界!", 16, "Times New Roman", u8"宋体");auto p4 = doc.AppendParagraph();p4.SetAlignment(Paragraph::Alignment::Centered);auto p4r1 = p4.AppendRun("Sample text here...", 12, "Arial");p4r1.AppendLineBreak();p4r1.SetCharacterSpacing(Pt2Twip(2));auto p4r2 = p4.AppendRun("And another line of sample text here...");p4r2.SetFontSize(14);p4r2.SetFont("Times New Roman");p4r2.SetFontColor("FF0000");p4r2.SetFontStyle(Run::Bold | Run::Italic);//doc.SetReadOnly();doc.Save("basic.docx");return 0;
}

实验成功后,就让DeepSeek帮助改写迁移代码。
提示词如下:

我有一个生成docx文档的程序,它调用的duckx类需要预先准备模板文件,不方便,现在准备迁移到minidocx类,它能直接生成文件,请用示例cpp中的调用方法来改写DOCXGlobal中的函数。
生成内容如下:

struct DOCXGlobalState : public FormatGlobalState {unique_ptr<docx::Document> document;explicit DOCXGlobalState(string file_path) {this->file_path = std::move(file_path);        std::cout << this->file_path << std::endl;// 直接创建新的Document对象,不需要模板文件document = make_uniq<docx::Document>();}~DOCXGlobalState() {DEBUG_LOG("~DOCXGlobalState开始");if (document) {document->Save(this->file_path);}}
};unique_ptr<GlobalFunctionData> InitializeGlobal(ClientContext &context,const string &file_path,const vector<string> &names,const vector<LogicalType> &sql_types,FormatOptions &options_base) override {auto &options = dynamic_cast<DOCXWriteOptions&>(options_base);auto gstate = make_uniq<DOCXGlobalState>(file_path);auto &doc = *gstate->document;// 添加标题doc.AppendParagraph(options.title, 12, "Times New Roman").SetFontStyle(docx::Run::Bold);// 添加表头if (options.header) {string header_text;for (idx_t col = 0; col < names.size(); ++col) {if (col != 0) header_text += "\t";header_text += names[col];}auto header_p = doc.AppendParagraph(header_text, 12, "Times New Roman");header_p.SetFontStyle(docx::Run::Bold);}DEBUG_LOG("添加标题和表头 完成");return gstate;
}void WriteData(ExecutionContext &context,GlobalFunctionData &gstate_base,LocalFunctionData &lstate_base,DataChunk &input,const vector<string> &names,FormatOptions &options_base) override {auto &gstate = dynamic_cast<DOCXGlobalState&>(gstate_base);lock_guard<mutex> lock(gstate.write_mutex);auto &doc = *gstate.document;DEBUG_LOG("开始写入数据,行数: " << input.size());    for (idx_t row = 0; row < input.size(); row++) {string row_text;for (idx_t col = 0; col < input.ColumnCount(); col++) {if (col != 0) row_text += "\t";auto val = input.GetValue(col, row);row_text += val.IsNull() ? "NULL" : val.ToString();}doc.AppendParagraph(row_text, 12, "Times New Roman");}// 立即保存而不是等待析构DEBUG_LOG("立即保存DOCX文档");doc.Save(gstate.file_path);DEBUG_LOG("DOCX文档保存完成");
}

我将上述内容复制粘贴到原有的源代码文件,并把引用的头文件由#include "duckx.hpp"改成#include "minidocx.hpp"。再调整编译命令行为

g++ minidocx-0.6.0/src/minidocx.cpp minidocx-0.6.0/3rdparty/pugixml-1.13/*.cpp minidocx-0.6.0/3rdparty/zip-0.2.1/*.c copy_file6.cpp -o copymini -lduckdb -lxls -I /par/include -I /par/xlslib/xlslib/src -I minidocx-0.6.0/src -I minidocx-0.6.0/3rdparty/pugixml-1.13 -I minidocx-0.6.0/3rdparty/zip-0.2.1  -I xlslib/src -std=c++17

运行结果如下

./copymini
=== XLS导出成功 ===
=== XLSX导出成功 ===
/par/tmp_test_output.docx
=== DOCX导出成功 ===
tmp_auto_recognize.docx

一举完成了docx库的迁移。

http://www.dtcms.com/a/594221.html

相关文章:

  • 北流网站建设制作网站在线制作软件
  • 2025 创客匠人全球创始人 IP + AI 万人高峰论坛:教育创业者的破局密钥
  • 目前做网站框架设计软件教程
  • 如何在命令行中运行Dev-C++程序?
  • 哪里有服务好的网站建设wordpress模板导航类
  • 线性代数 - 齐次线性方程组的解 与满秩/降秩的关系
  • 做外贸的网站有哪几个公司网址怎么申请
  • 【图论 有向图 环 传递闭包】P8186 [USACO22FEB] Redistributing Gifts S|普及+
  • Java Map体系集合
  • [InvalidArgumentException] property not exists:app\model\xxxModel->id
  • 大模型AI应用,正在企业级赛道迅猛爆发
  • 网站运营方案设计we建站
  • 网站备案怎么在工信部信息核验网站关键词在线优化
  • MATLAB基于面积和重心预测精度的IOWA算子的模糊变权组合预测模型
  • torch.ones_like(input)功能
  • 蓝牙钥匙 第79次 蓝牙与5G/6G技术融合:构建下一代无线通信新生态
  • 互联网创意网站有哪些方面二建注册成功在哪里查
  • DeepSeek邮件管理全攻略
  • 做外贸网站能用虚拟主机吗怎样用flash做游戏下载网站
  • pc端的移动端网站建设广东中山网站建设 光龙
  • 11.3 QGIS地图图表直方图应用和二次开发实现
  • 使用 LoRA 高效微调 Qwen 模型:从入门到实战
  • 如何做网站的维护和推广专业做网站照片
  • 惠州企业网站seo公司html5网站地址
  • 欧芯LKS32MC07
  • 创建大型网站专业网站制作哪里好
  • 算法215. 数组中的第K个最大元素
  • 巩义网站推广优化网站开发的软件环境
  • K8s资源控制器的实战
  • ppt超链接网站怎么做创建网站的六个步骤