XLSReadWriteII 7 is released – faster reading and writing, new sheet viewer, CSS formatting. See what’s new
Home / C++ Libraries / DOCXReadWrite example

DOCXReadWrite for C++

How to add a paragraph with formatted text.

C++ Builder

#include "DOCXReadWriteVcl.hpp"
using namespace DOCXReadWriteVcl;

TDOCXReadWriteVcl* DOCX;
DOCX = new TDOCXReadWriteVcl(nullptr);
TAXWLogPara *Para;
TAXWCHPX *CHPX;
CHPX = new TAXWCHPX(DOCX->Editor->MasterCHP);
Para = DOCX->Editor->Paras->AppendPara();
CHPX->Size = (double)24;
CHPX->FontName = "Times New Roman";
CHPX->Bold = true;
Para->AppendPlainText(CHPX, "Lorem ");
CHPX->Bold = false;
CHPX->TColor = (unsigned int)clRed;
Para->AppendPlainText(CHPX, "ipsum ");
CHPX->FillTColor = (unsigned int)clBlack;
Para->AppendPlainText(CHPX, "dolor ");
CHPX->FillTColor = (unsigned int)clWhite;
Para->AppendPlainText(CHPX, "sit amet.");
delete CHPX;
delete DOCX;

GCC and MSVC

#include "DOCXReadWriteVcl.hpp"
using namespace DOCXReadWriteVcl;

// MSVC must call AxInitialization
// AxInitialization();
TDOCXReadWriteVcl *DOCX;
TAXWLogPara *Para;
TAXWCHPX *CHPX;
TAXWPAPX *PAPX;
DOCX = new TDOCXReadWriteVcl();
DOCX->Create(nullptr);
Para = DOCX->Editor()->Paras()->AppendPara();
CHPX->Size((double)24);
CHPX->FontName(L"Times New Roman");
CHPX->Bold(true);
Para->AppendPlainText(CHPX, L"Lorem ");
CHPX->Bold(false);
CHPX->TColor((uint32_t)clRed);
Para->AppendPlainText(CHPX, L"ipsum ");
CHPX->FillTColor((uint32_t)clBlack);
Para->AppendPlainText(CHPX, L"dolor ");
CHPX->FillTColor((uint32_t)clWhite);
Para->AppendPlainText(CHPX, L"sit amet.");
delete CHPX;
delete DOCX;
// MSVC must call AxFinalization
// AxFinalization();

Download the C++ trial   XLSReadWriteII example →