How to use DOCXReadWrite

Type: TAXWLogEditor

The document text is stored in paragraph objects, equal to the text's paragraphs. There is one main document, the Editor property of the component. Other text parts, like headers, footers and text boxes are stored as sub documents. These are of the same type as the main document, TAXWLogEditor


Objects that can have text has a PlainText and/or FileText property for reading/writing text. PlainText is text without special characters. FileText is text with codes like CR/LF and Tab.


The Assign method is implemented on all objects where it's relevant to assign anything. This make it easy to copy parts of the document.

Character formatting

Character formattings are stored in a list called CHPX (CHaracter Properties eXeptions). This list contains formattings that are not the same as the master (CHP, CHaracter Properties) list. The master list is the MasterCHP property of the document.

Paragraph formatting

paragraph formattings are stored in a list called PAPX (PAragraph Properties eXeptions). This list contains formattings that are not the same as the master (PAP, PAragraph Properties) list. The master list is the MasterPAP property of the document.

Type: TAXWLogPos

Positions are used to move around in the document. A position can be moved by the character, word, paragraph, offset and more.

Type: TAXWLogSelection

Selections are used to edit text. A selection consists of two positions, FirstPos and LastPos. Move the positions to the part of text you want to edit. A Selection can also be used for other operations, such as making a bookmark of the text or add/remove bullets and numberings.

Key objects

Here are the most important objects of DOCXReadWrite listed. Only a few methods and properties are included to give a picture of how it works.

type TDOCXReadWrite = class(TDOCXComponent)
     procedure LoadFromFile(const AFilename: AxUCString);
     procedure SaveToFile(const AFilename: AxUCString);

     property Editor: TAXWLogDocEditor read FEditor;
type TAXWLogDocEditor = class(TAXWLogDocument)
     //! Assign ADoc to this document. If AAssignText is False, not text is assigned.
     procedure Assign(ADoc: TAXWLogDocEditor; AAssignText: boolean = True);
     //! The paragraphs of the document.
     property Paras      : TAXWLogParas read FLogParas;
     property Styles     : TAXWStyles read FStyles;
     property Numberings : TAXWNumberings read FNumberings;
     property Hyperlinks : TAXWHyperlinks read FHyperlinks;
     property Bookmarks  : TAXWBookmarks read FBookmarks;
     property Comments   : TAXWComments read FComments;
     property Pictures   : TAXWPictures read FPictures;
     property MasterCHP  : TAXWCHP read GetMasterCHP;
     property MasterPAP  : TAXWPAP read GetMasterPAP;
     property Headers    : TAXWHeadersFooters read FHeaders;
     property Footers    : TAXWHeadersFooters read FFooters;
type TAXWLogParas = class(TObjectList)
     procedure Assign(AParas: TAXWLogParas; AAssignText: boolean = True);

     function  AppendPara: TAXWLogPara; overload;
     function  InsertPara(AIndex: integer): TAXWLogPara;
     procedure AppendStrings(AStrings: TStrings); overload;
     property Paras[Index: integer]: TAXWLogPara read GetParas; default;
type TAXWLogPara = class(TAXWLogParaItem)
     procedure Assign(APara: TAXWLogPara; AAssignText: boolean = True);
     procedure AppendPlainText(const AText: AxUCString); overload;
     procedure AppendPlainText(ACHPX: TAXWCHPX; const AText: AxUCString); overload;
     function  AppendBookmark(const AName: AxUCString): TAXWBookmark; overload;
     function  AppendHyperlink(const AAddress,AText: AxUCString): TAXWHyperlink; overload;
     function  AppendPicture(const AFilename: AxUCString): TAXWGraphicPicture; overload;
     procedure AppendField(const AText, AInstr: AxUCString); overload;
     function  AppendComment(const AAuthor,AText: AxUCString): TAXWComment; overload;
     procedure AppendTab;
     // ACharPos is the character offset within the paragraph.
     procedure InsertPlainText(ACharPos: integer; const AText: AxUCString);     
     property PlainText: AxUCString read GetPlainText write SetPlainText;
     property PAPX     : TAXWPAPX read FPAPX;

Create the component and add some text:

  DOCXReadWrite, AXWLogParas;

  FDOCX: TDOCXReadWrite;
  Para: TAXWLogPara;
  FDOCX := TDOCXReadWrite.Create(Nil);
    // Add a paragraph.
    Para := FDOCX.Editor.Paras.AppendPara;
    // Assign text.
    Para.PlainText := 'Curabitur mi purus, pretium non condimentum vitae, vestibulum nec massa.';

Copyright (c) 2021 Axolot Data