docxcpp开源库,用于读写docx
docxcpp下载地址https://github.com/yunxingluoyun/docxcppC.docx读写库基于 pugixml 和 miniz 实现。能力概览分类支持内容文档打开 / 创建 / 保存.docx段落新增段落、标题、分页符、样式段落、多 Run 段落Run粗体、斜体、下划线、字号、字体、颜色、高亮段落格式对齐、缩进、段前段后、行距固定/多倍/至少、Tab Stops、分页控制表格创建、加行/列、嵌套表格、单元格合并图片正文/单元格插入支持文件路径和字节缓冲超链接正文和表格单元格中的外部超链接批注段落级批注的写入与读取页面设置页面尺寸、方向、页边距、Header/Footer 距离、Gutter支持pt/mm/cm/inches/twipsSectionSection Break、多 Section 读取、Header/Footer 内容文本/段落读取段落、Runs、表格、图片元数据、批注元数据、超链接、Section 配置项目结构include/docxcpp/ 头文件 src/ 实现 examples/ 示例 tests/ 测试含 python-docx 回归验证 3rdparty/ pugixml、miniz构建依赖构建docxcpp本身需要C17 编译器CMake 3.20Python 3其中pugixml和miniz已内置在仓库3rdparty/目录中不需要额外安装Python 3 主要用于运行部分测试如果只是在你自己的项目里链接已安装好的docxcpp则不需要额外再关心pugixml和miniz库构建默认构建默认情况下会构建静态库cmake-S.-Bbuild cmake--buildbuild构建静态库cmake-S.-Bbuild-static-DBUILD_SHARED_LIBSOFF cmake--buildbuild-static构建动态库docxcpp支持跨平台构建共享库cmake-S.-Bbuild-shared-DBUILD_SHARED_LIBSON cmake--buildbuild-shared安装库静态库和动态库都可以通过cmake --install安装cmake--installbuild-static--prefix/your/install/prefix cmake--installbuild-shared--prefix/your/install/prefix安装后会导出头文件docxcpp库文件docxcppConfig.cmakedocxcppTargets.cmake默认模板已内嵌到库中所以安装后的.dll/.so/.dylib不依赖源码目录。外部项目使用安装后可通过 CMake 包导入find_package(docxcpp CONFIG REQUIRED) target_link_libraries(your_target PRIVATE docxcpp::docxcpp)如果库安装在非系统默认路径可以在配置你的项目时传入cmake-S.-Bbuild-DCMAKE_PREFIX_PATH/your/install/prefix测试完整测试ctest --test-dir build --output-on-failure其中ctest包含常规读写回归python-docx双向互通回归安装烟雾测试把当前构建安装到临时前缀再用独立外部 CMake 工程通过find_package(docxcpp)链接并运行示例最小示例— examples/minimal.cppdocxcpp::Document document;document.add_paragraph(Hello, World!);document.add_heading(A Heading,1);document.save(output.docx);完整示例— examples/full_feature_5_pages.cpp覆盖标题、混合 Run、段落格式、表格含嵌套与合并、图片、超链接、批注、Section Break、Header/Footer。读取已有文档— examples/read_existing.cpp用于演示如何打开现有.docx读取段落、表格、批注、图片和 section 摘要。页面、分节、页眉页脚— examples/sections_headers_footers.cpp用于演示Section、页面尺寸、页边距、首页不同、奇偶页不同以及页眉页脚段落。字符样式与表格样式— examples/styles_and_tables.cpp用于演示字符样式引用、表格样式引用、插入段落、单元格合并和嵌套表格。页面单位示例document.set_page_size(docxcpp::StandardPageSize::A4);document.set_page_margins(docxcpp::PageMargins{docxcpp::Inches(1.0),docxcpp::Cm(2.0),docxcpp::Inches(1.0),docxcpp::Cm(2.0),docxcpp::Pt(36),docxcpp::Pt(24),docxcpp::Twips(360),});也可以直接指定常见标准纸型document.set_page_size(docxcpp::StandardPageSize::A0);document.set_page_size(docxcpp::StandardPageSize::B5);document.set_page_size(docxcpp::StandardPageSize::Letter);document.add_section_break(docxcpp::Section(docxcpp::StandardPageSize::Legal));字体样式示例docxcpp::RunStyle style;style.font_nameArial;style.character_style_nameEmphasis;style.east_asia_font_nameMicrosoft YaHei;style.complex_script_font_nameAmiri;style.all_capstrue;style.striketrue;style.superscripttrue;样式引用示例document.add_table(3,4,Light Shading Accent 1);document.set_table_style(0,Medium Grid 1 Accent 1);docxcpp::RunStyle run_style;run_style.character_style_idStrong;document.add_styled_paragraph(Styled by character style,run_style);与 python-docx 对比详见 docxcpp_vs_python_docx.md。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2593345.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!