OpenWord 1.0.0
Modern C++17 library for parsing, manipulating, and saving DOCX files.
Loading...
Searching...
No Matches
OpenWord

📖 OpenWord

A modern, high-performance C++17 library for creating, parsing, and manipulating Microsoft Word (.docx) files.
CI Docs C++17 Rust License: MIT

OpenWord stands out by offering a unique hybrid Rust/C++ math engine, providing seamless out-of-the-box support for translating LaTeX and MathML directly into native Word equations (OMML).

It is built with a zero-compromise approach to performance and safety, strictly adhering to the C++ Core Guidelines (Microsoft GSL) and utilizing a fluent, ergonomic API design.

✨ Key Features

  • 🧮 Native Equations: Convert LaTeX and MathML directly to Word OMML using a blazing-fast Rust bridge.
  • 🎨 Rich Formatting: Fluent API chaining for text runs, custom colors, spacing, line breaks, and highlights.
  • 📊 Advanced Tables: Full support for nested tables, cell merging (rowspan/colspan), borders, and shading.
  • 📑 Layout & Structure: Multi-section documents, independent headers/footers, dynamic page numbers, and custom margins.
  • 📝 Lists & Styles: One-click bullet/numbered list generation and comprehensive style inheritance trees (docDefaults).
  • 💬 Annotations: Built-in support for document comments, footnotes, endnotes, and metadata injection.
  • 📦 Zero Deployment Friction: XSLT stylesheets and math engine assets are statically embedded directly into the binary.

📚 Documentation

🛠 Technical Stack

OpenWord automatically manages its C++ dependencies via CMake FetchContent. No manual downloads required.

  • C++17: Core library architecture.
  • Rust (2021): LaTeX to MathML conversion (via tex2math).
  • libxml2 & libxslt: Lightning-fast XML manipulation and MathML-to-OMML XSLT transformations.
  • pugixml: Zero-allocation DOM parsing.
  • libzip: Secure .docx archive packing.
  • Catch2: Extensive automated test matrix.

🚀 Quick Start

Prerequisites

  • CMake 3.15+
  • C++17 Compiler (GCC 9+, Clang 10+, Apple Clang, or MSVC 2019+)
  • Rust Toolchain (cargo)

Build Instructions

1. Compile the Rust Math Engine

cd rust_math_engine
cargo build --release
cd ..

2. Configure and Build the C++ Project

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j 4

3. Run the Test Suite & Demo

cd build
ctest --output-on-failure -C Release
./openword_demo

💻 Usage Example

OpenWord features a highly ergonomic, modern C++ API designed to reduce boilerplate.

int main() {
// 1. Fluent Text Formatting
auto p = doc.addParagraph("Welcome to ");
p.addRun("OpenWord").setBold(true).setColor(openword::Color(0, 128, 255));
// 2. Hybrid Rust Math Engine (LaTeX to Native Word Equation)
std::string omml = doc.convertLaTeXToOMML("\\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}");
// 3. Ergonomic Tables
auto t = doc.addTable(2, 2);
t.cell(0, 0).addParagraph("Top Left");
t.cell(1, 1).addParagraph("Nested tables are supported too!");
doc.save("demo_output.docx");
return 0;
}
Paragraph addParagraph(const std::string &text="")
Represents the main Office Open XML Word document (.docx).
Definition Document.h:588
Table addTable(int rows, int cols)
Nests a new table inside this cell.
std::string convertLaTeXToOMML(const std::string &latex) const
Paragraph addParagraph(const std::string &text="")
bool save(gsl::czstring filepath)
Run addRun(const std::string &text="")
void addEquation(const std::string &omml)
Adds a raw OMML (Office Math Markup Language) equation to the paragraph.
Run & setBold(bool val=true)
Run & setColor(const Color &color)
Table & setBorders(const BorderSettings &all)
Cell cell(int row, int col)
Definition Document.h:74
Definition Document.h:42

⚖️ License

OpenWord is released under the MIT License. Reference libraries located in third_party/ belong to their respective owners.