1. Products
  2.   Word Processing
  3.   C++
  4.   DuckX  

DuckX  

 
 

Open Source C++ API for Word OOXML Documents

 Create, Read, Update and Export Microsoft Office Word DOCX Files inside C++ Applications.

DuckX is an Open Source free C++ Library that enables software developers to work with Microsoft Word (DOCX) inside their own applications. The API can read, write and edit MS Word documents, which have the .docx file extension.

The API is very stable and provides support for many important Word processing features such as creating and saving DOCX documents, paragraph addition, heading, inserting text, adding tables, adding images, paragraph styles, applying text formatting, and much more.

Previous Next

Getting Started with DuckX

The preferred way is to create a build folder.

Create Build Folder for DuckX

git clone https://github.com/amiremohamadi/DuckX.git
cd DuckX
mkdir build
cd build
cmake ..
cmake --build;

C++ API to Open and Read Word DOCX Documents

DuckX library enables software professional to open an existing word DOCX documents inside their own applications without using Microsoft Word. You can go over paragraphs, runs, and print them. It also gives functionality for modifying word documents, You also can add images, text, fonts, text formatting and more.

How to Open and Read Word Documents via C++ API

#include 
#include 

int main() {

    duckx::Document doc("file.docx");   

    doc.open();

    for (auto p : doc.paragraphs())
	for (auto r : p.runs())
            std::cout << r.get_text() << std::endl;
}

Insert & Rdad Table inside Word DOCX File

DuckX library gives developers the capability to insert tables into a Word DOCX Document inside C++ applications. MS Word tables play a very important role in laying out well-formatted data. Tables are a good way of presenting data in rows and columns. They are very simple to insert and manipulate in Word files.

Table Reading Support in Word Documents via C++ API

#include "../src/duckx.hpp"
using namespace std;

// Print a paragraph and all children runs
void print_paragraph(duckx::Paragraph& p) {
	for (auto r = p.runs(); r.has_next(); r.next()) {
		cout << r.get_text() << endl;
	}
}

int main() {
    duckx::Document doc("my_test.docx");
    doc.open();

	cout << "Paragraph content:" << endl;
    for (auto p = doc.paragraphs(); p.has_next(); p.next()) {
        for (auto r = p.runs(); r.has_next(); r.next()) {
            cout << r.get_text() << endl;
        }
		print_paragraph(p);
    }

	cout << "Table content:" << endl;
	for (auto t = doc.tables(); t.has_next(); t.next()) {
		for (auto tr = t.rows(); tr.has_next(); tr.next()) {
			for (auto tc = tr.cells(); tc.has_next(); tc.next()) {
				for (auto p = tc.paragraphs(); p.has_next(); p.next()) {
					print_paragraph(p);
				}
			}
		}
	}

    return 0;
}

Adding Images to Word DOCX Files

DuckX library provides functionality for inserting images inside Word DOCX document. To add an image you need to provide the name and location of the image. Developers also can specify both the width and height of the image.

 English