AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / Desarrollar una aplicación o un sitio web / Controles, ventanas y páginas / Controles: tipos disponibles / Control Procesador de texto
  • Presentación
  • Manipulación de controles Procesador de texto mediante programación
  • 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
  • Word Processing control properties
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Presentación
Word Processing controls can be manipulated programmatically.
To handle the Word Processing control, WLanguage proposes:
  • a set of functions used to perform all the common operations (direct programming via the WLanguage DocXXX functions. For more details, see Word Processing control functions.
  • an advanced programming via the different advanced types of WLanguage used to directly handle the content of the docx file displayed by the Word Processing control. For more details, see Types associated with the Word Processing control.
This help page explains how to programmatically manipulate Word Processing controls.
Manipulación de controles Procesador de texto mediante programación

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:
    // Select a .docx file in the current directory
    sFileName is string
    sFileName = fSelect("", "presentation.docx", ...
    	"Selecting DocX files", ...
    	"Docx file (*.docx)" + TAB + "*.docx", "*.docx", fselOpen)
    
    IF sFileName ~= "" THEN
    	// No selected file
    	RETURN
    END
    
    // Load the docx file
    WP_MyDocument = sFileName
  • use <Word Processing>Abrir.
    For example:
    WP_MyDocument = Open("C:\Users\test\Documents\file.docx")
    IF ErrorOccurred() THEN
    	Error(ErrorInfo())
    RETURN
  • use a Document variable and assign it to the Word Processing control.
    For example:
    MyDocument is Document
    MyDocument = "C:\temp\presentation.docx"
    WP_MyDocument = MyDocument

    or:
    MyDocument is Document
    MyDocument = DocOpen("C:\Users\test\Documents\file.docx")
    IF ErrorOccurred() THEN
    	Error(ErrorInfo())
    ELSE
    	WP_MyDocument = MyDocument
    END
Please note: only files in docx format can be manipulated by the Word Processing control.
Tip To display an empty document in a Word Processing control, simply assign the Word Processing control with an empty string.
Example:
// Create a blank document
WP_MyDocument = ""

Saving a docx document

To save a docx document, all you have to do is use <Word Processing>Guardar.
Example:
// Choose the directory and the backup name
sFileName is string = fSelect(CompleteDir(fExeDir()),"presentation.docx", ...
"Selecting DocX files","Docx file (*.docx)" + TAB + "*.docx" , "*.docx", fselCreate)
 
// Save the file
WP_NoName1.Save(sFileName)
 
IF ErrorOccurred THEN
Error(StringBuild("The %1 file was not saved.", sFileName), ErrorInfo())
RETURN
END
Remarks:

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:
// Find "BEAUTIFUL" in the text
// Selects the first one found to change its color
arrFragments is array of docFragments = WP_NoName1.Find("BEAUTIFUL")
 
IF arrFragments.Count >= 1 THEN
// Position the cursor at the beginning of the first word found
WP_NoName1.Cursor = arrFragments[1].StartPosition
// Calculate the selection length
WP_NoName1.SelectionLength = ...
arrFragments[1].EndPosition - arrFragments[1].StartPosition+1
// Modify the text color
arrFragments[1].Formatting.TextColor = PastelRed
BREAK
END
In this code, the docFragment variable corresponds to the text section containing the searched word, as well as its position in the entire 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:
// Change the selection color
// Get the current selection
MySelection is docFragment(WP_MyDocument, WP_MyDocument.Cursor, ...
		WP_MyDocument.SelectionLength)
// Change the color
MySelection.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:
    // Insert a text at the end of document 
    frag2 is docFragment(WP_MyDoc, -1 , 0)
    frag2.Text += "End text"
  • Inserting a text from a given position with <Word Processing>.Insert.
    WP_Document.Insert(WP_Document.Cursor, "My inserted text")
  • 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:
    <Word Processing control> = "Text to insert"
    Example:
    WP_MyDocument = "I am the first sentence of this document."
  • add the text with <Word Processing>.add.
  • insert a fragment in first position. Example:
    // sInitialText contains the text to insert 
    frag is docFragment(WP_MyDoc, WP_MyDoc.Cursor, 0)
    frag.Text += sInitialText
  • insert a text from position 1 with <Word Processing>.Insert.
    WP_Document.Insert(1, "My inserted text")

Adding a page break into a document

The following code is used to add a page break into a document:
// Add a page break 
WP_NoName1.Add(Charact(12))
You can also use the following constants to add the desired type of break to a document or fragment:
  • docColumnJump: Adds a column jump to a multicolumn section. If the section is not multicolumn, a page break is added.
  • docLineFeed: Adds a line feed.
  • docPageFeed: Adds a page feed.
  • docParagraphJump: Adds a paragraph break.
Example:
// Add a page break 
WP_NoName1.Add(docPageBreak + "Text on next page")

Management of bookmarks

You have the ability to manage bookmarks in a Word Processing document. For example:
  • Add a bookmark: Adds a bookmark named MyBookmark with the selected text.
    doc is Document
    doc <- WP_MyDocument
    fragSelection is docFragment = TT_MyDocument.Selection.Fragment
    doc.Bookmark["MyBookmark"] = fragSelection
  • Delete a bookmark: Deletes the bookmark with the name Bookmark1:
    doc is Document
    doc <- WP_MyDocument
    Delete(doc.Bookmark, "Bookmark1")
  • List bookmarks: Lists the bookmarks of a document:
    doc is Document 
    doc <- WP_MyDocument
    FOR EACH uABookmark,BookmarkName of doc.Bookmark
    	Trace(BookmarkName) // Bookmark name
    	Trace(uABookmark.Text) // Bookmark text
    END
  • Inserting a text at the end of bookmark:
    doc is Document <- TT_MonDocument.Valeur
    // Recherche de la position du signet 
    fragmentSignet is docFragment = doc.Bookmark["Signet 1"]
    IF fragmentSignet <> Null THEN
    	// Insertion du texte à la fin du signet
    	let nPositionInsertion = fragmentSignet.EndPosition
    	// Insertion à proprement dite
    	TT_MonDocument.Insère(nPositionInsertion, "Texte à insérer à la position du signet")
    ELSE
    	Error("Signet 'Signet 1' non trouvé dans le document")
    END

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:
MonDocument is Document = "c:\temp\conditiongenerales.docx"

// Impression dans le visualisateur de rapports
iDestination(iViewer)
// Ajout des états dans l'enchaînement
iSequencingAdd(ETAT_Etat1)
iSequencingAdd(ETAT_Etat2, 3)
// Ajout des conditions générales sous forme d'un document
iSequencingAddDoc(MonDocument)
iSequencingPrint()
For more details, see Sequencing reports.

Word Processing control properties

The following properties are specific to the Word Processing control. They are mainly used to handle the control characteristics:
AutoCorrectLa propiedad AutoCorrect permite definir un conjunto de correcciones automáticas que se aplicarán en un control Procesador de texto a medida que el usuario escribe.
AutomaticLinkThe property AutomaticLink property allows you to:
  • determine if the automatic link detection mode is enabled,
  • enable or disable the automatic link detection mode.
DisplayBookmarksLa propiedad DisplayBookmarks permite:
  • identificar el modo de visualización de los marcadores en un control Procesador de texto.
  • activar o desactivar los marcadores en un control Procesador de texto.
DisplayFormattingMarksLa propiedad DisplayFormattingMarks permite:
  • Determinar si las marcas de formato están activadas o desactivadas en un control Procesador de texto.
  • Activar o desactivar las marcas de formato en un control Procesador de texto.
DisplayModeThe DisplayMode property gets and changes:
  • the display mode in a Word Processing control,
  • the display mode in a PDF Reader control
  • the display mode in an HTML Editor control,
  • the display mode in a Kanban control
FilePathLa propiedad FilePath permite obtener:
  • el nombre del archivo xlsx asociado a un control Hoja de cálculo.
  • el nombre del archivo asociado a un control Editor de imágenes.
  • el nombre del archivo PDF asociado a un control Lector PDF.
  • el nombre del archivo DOCX asociado a un control Procesador de texto.
  • el nombre del archivo wddiag asociado a un control Editor de diagramas.
FormattingMarksColorLa propiedad FormattingMarksColor permite:
  • obtener el color de las marcas de formato en un control Procesador de texto.
  • cambiar el color de las marcas de formato en un control Procesador de texto.
HTMLEditThe property EditionHTML property property allows you 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.
NumberAccessiblePagesThe NumberAccessiblePages property is used to get the number of pages currently loaded in a PDF Reader or Word Processing control.
NumberDisplayedPageLa propiedad NumberDisplayedPage permite identificar y cambiar el número de la página que se muestra actualmente en el control Lector PDF o Procesador de texto.
NumberPageThe property PageNumber property is used to identify:
  • 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.
RuleVisibleThe property RuleVisible property allows you 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.
SelectionThe property Selection property displays the characteristics of the selection (or cursor):
  • in a Word Processing control.
    Note: This selection is located in the part being edited (body, header or footer).
  • in a Spreadsheet control.
  • in an HTML Editor control.
  • in a Diagram Editor control.
SelectionLengthThe SelectionLength property gets and sets the length of the selection made in a Word Processing control.
ToolbarVisibleLa propiedad ToolbarVisible permite:
  • determinar si la barra de herramientas o la cinta de opciones se muestra en un control.
  • mostrar u ocultar la barra de herramientas o la cinta de opciones en un control.
For a complete list of WLanguage properties that can be used with Word Processing controls, see Word Processing control properties.
Versión mínima requerida
  • Versión 24
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 23/11/2024

Señalar un error o enviar una sugerencia | Ayuda local