How to use DOCXReadWrite
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 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 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.
Positions are used to move around in the document. A position can be moved by the character, word, paragraph, offset and more.
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.
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) public procedure LoadFromFile(const AFilename: AxUCString); procedure SaveToFile(const AFilename: AxUCString); property Editor: TAXWLogDocEditor read FEditor; end; type TAXWLogDocEditor = class(TAXWLogDocument) public //! 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; end; type TAXWLogParas = class(TObjectList) public 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; end; type TAXWLogPara = class(TAXWLogParaItem) public 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; end;
Create the component and add some text:
uses DOCXReadWrite, AXWLogParas; var FDOCX: TDOCXReadWrite; Para: TAXWLogPara; begin FDOCX := TDOCXReadWrite.Create(Nil); try // Add a paragraph. Para := FDOCX.Editor.Paras.AppendPara; // Assign text. Para.PlainText := 'Curabitur mi purus, pretium non condimentum vitae, vestibulum nec massa.'; finally FDOCX.Free; end; end;
Copyright (c) 2021 Axolot Data