How can I highlight replaced text in a Microsoft Word Document using MATLAB?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 16 Fév 2023
Réponse apportée : MathWorks Support Team
le 17 Fév 2023
I am writing a script using the MATLAB 'actxserver' object to create a Word Application COM Server to work with a Word Document like so:
word = actxserver('Word.Application');
word.Documents.Open(fpath);
I am trying to find instances of a string in the document, replace them all with a different string, and highlight the new instances of the replaced word. How can I do this?
Réponse acceptée
MathWorks Support Team
le 16 Fév 2023
While it is possible to change many parameters of the 'Replacement' text, including whether or not the replaced text is highlighted, it is not possible to directly set the color of the highlighting itself in this case.
As a result, it is a bit more complicated to highlight replaced instances of a string only, meaning no instances of the replacement string that were in the document prior to the replacement operation will be highlighted. However, it is possible by utilizing the document 'Options' object, and changing the 'DefaultHighlightColorIndex'. This can be done in MATLAB like so:
options = word.Options;
% Set the default highlight color
options.DefaultHighlightColorIndex = <insert WdColorIndex enumerator value here>;
% Activate the replacement text to be highlighted
selection.Find.Replacement.Highlight = 1;
For a full list of WdColorIndex enumerator values, please see the following Microsoft documentation page:
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Use COM Objects in MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!