PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Overview
  • Handling the Word Processing control through programming
  • Opening and creating a docx document in a Word Processing control
  • Saving a docx document
  • Performing a search in a document and modifying the search result
  • Handling the selection
  • Adding text into a document
  • Adding a page break into a document
  • Management of bookmarks
  • Sequencing reports and Word Processing documents
  • Properties associated with the Word Processing control
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
A Word Processing control can be handled through programming.
To handle the Word Processing control, WLanguage proposes:
This help page explains how to handle a Word Processing control through programming. Caution: This documentation presents the last features of the Word Processing control. Make sure that all the necessary modules are updated.
Handling the Word Processing control through programming

Opening and creating a docx document in a Word Processing control

To open an existing docx document through programming in a Word Processing control, you can:
  • assign the docx file to the Word Processing control. For example:
    // Sélectionne un fichier .docx dans le répertoire en cours
    sNomFichier is string
    sNomFichier = fSelect("", "présentation.docx", ...
    "Sélection de fichier DocX", ...
    "Fichier Docx (*.docx)" + TAB + "*.docx", "*.docx", fselOpen)
     
    IF sNomFichier ~= "" THEN
    // Aucun fichier sélectionné
    RETURN
    END
     
    // Chargement du fichier docx
    TT_MonDocument = sNomFichier
  • use <Word Processing>.Open.
    For example:
    TT_MonDocument.Ouvre("C:\Users\test\Documents\fichier.docx")
     
    SI ErreurDétectée() ALORS
    Erreur(ErreurInfo())
    RETOUR
  • use a Document variable and assign it to the Word Processing control.
    For example:
    MonDocument is Document
    MonDocument = "C:\temp\presentation.docx"
    TT_MonDocument = MonDocument

    or:
    MonDocument is Document
    MonDocument = DocOpen("C:\Users\test\Documents\fichier.docx")
    IF ErrorOccurred() THEN
    Error(ErrorInfo())
    ELSE
    TT_MonDocument = MonDocument
    END
Caution: only the files in docx format can be handled by the Word Processing control.
Tip: To display an empty document in a Word Processing control, all you have to do is assign an empty string to the Word Processing control.
Example:
// Création d'un document vierge
TT_MonDocument = ""

Saving a docx document

To save a docx document, all you have to do is use <Word Processing>.Save.
Example:
// On choisit le répertoire et le nom de sauvegarde
sNomFichier est une chaîne = fSélecteur(ComplèteRep(fRepExe()), "présentation.docx", ...
"Sélection de fichiers DocX","Fichier Docx (*.docx)" + TAB + "*.docx" , "*.docx", fselCrée)
 
// On sauvegarde le fichier
TT_SansNom1.Sauve(sNomFichier)
 
SI ErreurDétectée ALORS
Erreur(ChaîneConstruit("Le fichier %1 n'a pas pu être enregistré.", sNomFichier), ErreurInfo())
RETOUR
FIN
Notes:

Performing a search in a document and modifying the search result

To perform a search in a Word Processing document, all you have to do is use <Word Processing>.Seek.
Example:
// Recherche du mot "BEAUGRAND" dans le texte
// Sélectionne uniquement le premier trouvé pour changer sa couleur
tabFragments est tableau de docFragments = TT_SansNom1.Recherche("BEAUGRAND")
 
SI tabFragments.Occurrence >= 1 ALORS
// Positionnement du curseur au début du premier mot trouvé
TT_SansNom1.Curseur = tabFragments[1].PositionDébut
// Calcul de la longueur de la sélection
TT_SansNom1.LongueurSélection = ...
tabFragments[1].PositionFin - tabFragments[1].PositionDébut+1
// Modification de la couleur du texte
tabFragments[1].MiseEnForme.CouleurTexte = RougePastel
SORTIR
FIN
In this code, the Variable docFragment corresponds to the portion of text containing the searched word, with its position in the complete text. Then, you have the ability to handle the fragment found.

Handling the selection

To handle the selection currently performed in a Word Processing control, you have the ability to retrieve this selection in a docFragment variable.
The following code is used to change the color of selected text.
Example:
// Changement de la couleur de la sélection
// Récupération de la sélection actuelle
MaSélection is docFragment(TT_MonDocument, TT_MonDocument.Curseur, ...
TT_MonDocument.LongueurSélection)
// Changement de la couleur
MaSélection.Formatting.TextColor = PastelRed
The docFragment variable owns a specific constructor used to easily retrieve the selection.

Adding text into a document

Several methods can be used to add text into an existing document:
  • Inserting a fragment at the desired position. Example:
    // Insère un texte à la fin du document
    frag2 is docFragment(TT_MonDoc, -1 , 0)
    frag2.Text += "Texte de fin"
  • Inserting a text from a given position with <Word Processing>.Insert.
    TT_Document.Insère(TT_Document.Curseur, "Mon texte inséré")
  • Adding a text at the end of document with <Word Processing>.Add.
To add text into an empty document, you can:
  • use the direct assignment of control:
    <Champ Traitement de texte> = "Texte à insérer"
    Example:
    TT_Mondocument = "Je suis la première phrase de ce document."
  • add the text with <Word Processing>.Add.
  • insert a fragment in first position. Example:
    // sTexteOriginal contient le texte à insérer
    frag is docFragment(TT_MonDoc, TT_MonDoc.Curseur, 0)
    frag.Text += sTexteOriginal
  • insert a text from position 1 with <Word Processing>.Insert.
    TT_Document.Insère(1, "Mon texte inséré")

Adding a page break into a document

The following code is used to add a page break into a document:
// Ajoute un saut de page
TT_SansNom1.Ajoute(Caract(12))
Versions 24 and later
You can also use the following constants to add the desired type of break to a document or fragment:
  • docColumnBreak: Adds a column break in a multicolumn section. If the section is not multicolumn, a page break is added.
  • docLineBreak: Adds a line break.
  • docPageBreak: Adds a page break.
  • docParagraphBreak: Adds a paragraph break.
Example:
// Ajoute un saut de page
TT_SansNom1.Ajoute(docSautDePage + "Texte sur la page suivante")
New in version 24
You can also use the following constants to add the desired type of break to a document or fragment:
  • docColumnBreak: Adds a column break in a multicolumn section. If the section is not multicolumn, a page break is added.
  • docLineBreak: Adds a line break.
  • docPageBreak: Adds a page break.
  • docParagraphBreak: Adds a paragraph break.
Example:
// Ajoute un saut de page
TT_SansNom1.Ajoute(docSautDePage + "Texte sur la page suivante")
You can also use the following constants to add the desired type of break to a document or fragment:
  • docColumnBreak: Adds a column break in a multicolumn section. If the section is not multicolumn, a page break is added.
  • docLineBreak: Adds a line break.
  • docPageBreak: Adds a page break.
  • docParagraphBreak: Adds a paragraph break.
Example:
// Ajoute un saut de page
TT_SansNom1.Ajoute(docSautDePage + "Texte sur la page suivante")
Versions 23 and later

Management of bookmarks

You have the ability to manage bookmarks in a Word Processing document. For example:
  • Adding a bookmark: Adds a bookmark named MyBookmark with the selected text.
    doc is Document
    doc <- TT_MonDocument
    fragSélection is docFragment = TT_MonDocument.Sélection.Fragment
    doc.Bookmark["MonSignet"] = fragSélection
  • Deleting a bookmark: Deletes the bookmark named Bookmark1:
    doc est un Document
    doc <- TT_MonDocument
    Supprime(doc.Signet, "Signet1")
  • Listing the bookmarks: Lists the document bookmarks:
    doc is Document
    doc <- TT_MonDocument
    FOR EACH uUnSignet,NomSignet of doc.Bookmark
    Trace(NomSignet) // Nom du signet
    Trace(uUnSignet.Texte) // Texte du signet
    END
  • Inserting a text at the end of bookmark:
    doc est un Document <- TT_MonDocument.Valeur
    // Recherche de la position du signet
    fragmentSignet est un docFragment = doc.Signet["Signet 1"]
    SI fragmentSignet <> Null ALORS
    // Insertion du texte à la fin du signet
    soit nPositionInsertion = fragmentSignet.PositionFin
    // Insertion à proprement dite
    TT_MonDocument.Insère(nPositionInsertion, "Texte à insérer à la position du signet")
    SINON
    Erreur("Signet 'Signet 1' non trouvé dans le document")
    FIN
New in version 23

Management of bookmarks

You have the ability to manage bookmarks in a Word Processing document. For example:
  • Adding a bookmark: Adds a bookmark named MyBookmark with the selected text.
    doc is Document
    doc <- TT_MonDocument
    fragSélection is docFragment = TT_MonDocument.Sélection.Fragment
    doc.Bookmark["MonSignet"] = fragSélection
  • Deleting a bookmark: Deletes the bookmark named Bookmark1:
    doc est un Document
    doc <- TT_MonDocument
    Supprime(doc.Signet, "Signet1")
  • Listing the bookmarks: Lists the document bookmarks:
    doc is Document
    doc <- TT_MonDocument
    FOR EACH uUnSignet,NomSignet of doc.Bookmark
    Trace(NomSignet) // Nom du signet
    Trace(uUnSignet.Texte) // Texte du signet
    END
  • Inserting a text at the end of bookmark:
    doc est un Document <- TT_MonDocument.Valeur
    // Recherche de la position du signet
    fragmentSignet est un docFragment = doc.Signet["Signet 1"]
    SI fragmentSignet <> Null ALORS
    // Insertion du texte à la fin du signet
    soit nPositionInsertion = fragmentSignet.PositionFin
    // Insertion à proprement dite
    TT_MonDocument.Insère(nPositionInsertion, "Texte à insérer à la position du signet")
    SINON
    Erreur("Signet 'Signet 1' non trouvé dans le document")
    FIN

Management of bookmarks

You have the ability to manage bookmarks in a Word Processing document. For example:
  • Adding a bookmark: Adds a bookmark named MyBookmark with the selected text.
    doc is Document
    doc <- TT_MonDocument
    fragSélection is docFragment = TT_MonDocument.Sélection.Fragment
    doc.Bookmark["MonSignet"] = fragSélection
  • Deleting a bookmark: Deletes the bookmark named Bookmark1:
    doc est un Document
    doc <- TT_MonDocument
    Supprime(doc.Signet, "Signet1")
  • Listing the bookmarks: Lists the document bookmarks:
    doc is Document
    doc <- TT_MonDocument
    FOR EACH uUnSignet,NomSignet of doc.Bookmark
    Trace(NomSignet) // Nom du signet
    Trace(uUnSignet.Texte) // Texte du signet
    END
  • Inserting a text at the end of bookmark:
    doc est un Document <- TT_MonDocument.Valeur
    // Recherche de la position du signet
    fragmentSignet est un docFragment = doc.Signet["Signet 1"]
    SI fragmentSignet <> Null ALORS
    // Insertion du texte à la fin du signet
    soit nPositionInsertion = fragmentSignet.PositionFin
    // Insertion à proprement dite
    TT_MonDocument.Insère(nPositionInsertion, "Texte à insérer à la position du signet")
    SINON
    Erreur("Signet 'Signet 1' non trouvé dans le document")
    FIN

Sequencing reports and Word Processing documents

You now have the ability to sequence reports and Word Processing documents.
To do so, iSequencingAddDoc must be used in addition to the standard functions for creating sequences of reports. For example:
MyDocument is Document = "c:\temp\generalconditions.docx"
 
// Print in the report viewer
iDestination(iViewer)
// Add reports into the sequence
iSequencingAdd(RPT_Report1)
iSequencingAdd(RPT_Report2, 3)
// Add the general conditions in document format
iSequencingAddDoc(MyDocument)
iSequencingPrint()
For more details, see Sequencing reports.

Properties associated with the Word Processing control

The following properties are specific to the Word Processing control. They are mainly used to handle the control characteristics:
Versions 11 and later
AutomaticLink
New in version 11
AutomaticLink
AutomaticLink
The AutomaticLink property is used to:
  • determine if the automatic link detection mode is enabled,
  • enable or disable the automatic link detection mode.
Versions 24 and later
DisplayBookmarks
New in version 24
DisplayBookmarks
DisplayBookmarks
The DisplayBookmarks property is used to:
  • identify the display mode of bookmarks in a Word Processing control.
  • show or hide bookmarks in a Word Processing control.
Versions 22 and later
DisplayControlCharacters
New in version 22
DisplayControlCharacters
DisplayControlCharacters
The DisplayControlCharacters property is used to:
  • Find out whether the display of control characters is enabled in a Word Processing control.
  • Enable (or not) the display of control characters in a Word Processing control.
Versions 23 and later
DisplayMode
New in version 23
DisplayMode
DisplayMode
The DisplayMode property is used to get and change the display mode of a Word Processing or PDF Reader control.
Versions 23 and later
FilePath
New in version 23
FilePath
FilePath
The FilePath property is used to identify:
Versions 25 and later
FormattingMarksColor
New in version 25
FormattingMarksColor
FormattingMarksColor
The FormattingMarksColor property is used to:
  • get the color of the formatting marks in a Word Processing control.
  • change the color of the formatting marks in a Word Processing control.
Versions 23 and later
HTMLEdit
New in version 23
HTMLEdit
HTMLEdit
The HTMLEdit property is used to:
  • find out whether a Word Processing control is displayed in optimized mode for HTML editing,
  • modify a Word Processing control to display it (or not) in optimized mode for HTML editing.
Versions 23 and later
NumberAccessiblePages
New in version 23
NumberAccessiblePages
NumberAccessiblePages
The NumberAccessiblePages property is used to get the number of pages currently loaded in a PDF Reader or Word Processing control.
Versions 23 and later
NumberDisplayedPage
New in version 23
NumberDisplayedPage
NumberDisplayedPage
The NumberDisplayedPage property is used to identify and change the number of the page currently displayed in the PDF Reader or Word Processing control.
Versions 09 and later
NumberPage
New in version 09
NumberPage
NumberPage
The NumberPage property is used to get:
  • the number of pages in a "multi-page" image file. This image is displayed in an Image control or in the background of a Chart control.
  • the number of pages in a PDF file displayed in an Image control.
  • the number of pages found in a PDF file displayed in a PDF Reader control.
  • the number of pages found in a DOCX file displayed in a Word Processing control.
Versions 22 and later
RuleVisible
New in version 22
RuleVisible
RuleVisible
The RuleVisible property is used to:
  • Find out whether the rulers are visible or invisible in a Word Processing control.
  • Make the rulers visible or invisible in a Word Processing control.
Versions 22 and later
Selection
New in version 22
Selection
Selection
The Selection property is used to get the characteristics of the selection (or cursor):
  • in the Word Processing control.
    Remark: This selection is in the section being edited in the control (body, header or footer).
  • in the Spreadsheet control.
  • in the HTML Editor control.
Versions 22 and later
SelectionLength
New in version 22
SelectionLength
SelectionLength
The SelectionLength property is used to get and change the length of the selection made in a Word Processing control.
Versions 20 and later
ToolbarVisible
New in version 20
ToolbarVisible
ToolbarVisible
The ToolbarVisible property is used to:
  • know if the toolbar or the ribbon is displayed in a control.
  • show or hide the toolbar or the ribbon in a control.
For a complete list of WLanguage properties that can be used with a Word Processing control, see Properties associated with the Word Processing control.
Minimum version required
  • Version 24
Comments
Click [Add] to post a comment